Reputation: 17478
How do I access a custom property from another Unity component?
In my Avatar component I have declared the variable like this:
public var isInEndzone : boolean;
Calling the property from another component:
//actor variable is the GameObject that has the Avatar component.
public var avatar : GameObject;
....
var avatarComponent : Avatar = avatar.GetComponent(Avatar);
if (avatarComponent.IsInEndzone){
//do something...
}
Error:
GetComponent requires that the requested component 'Avatar' derives from MonoBehaviour or Component or is an interface.
UnityEngine.GameObject:GetComponent(Type)
BCE0019: 'IsInEndzone' is not a member of 'UnityEngine.Avatar'.
Upvotes: 0
Views: 2334
Reputation: 2526
I GOT IT! You cannot use the reserved name Avatar, apparently that is already a class, change the name to something else and it will work.
Upvotes: 1