0

如何从另一个 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'. 
4

1 回答 1

1

我得到了它!您不能使用保留名称 Avatar,显然这已经是一个类,将名称更改为其他名称即可。

于 2013-07-23T13:27:10.860 回答