如何从另一个 Unity 组件访问自定义属性?
在我的 Avatar 组件中,我声明了这样的变量:
public var isInEndzone : boolean;
从另一个组件调用属性:
//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...
}
错误:
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'.