一个简单的错误,去过那里......实际上太多次了:)
我会这样解释:
GameObject 是一种类型。GameObject 类型只能与 GameObjects 或继承自 GameObject 的事物相关联。
这个的意思是:GameObject变量只能指向GameObjects和GameObject的子类。下面的代码指向一个GameObject类型的组件。
GameObject.Find("Cubey").GetComponent<GameObject>();
代码显示“查找 Cubey 并指向附加到 Cubey 的 GameObject”。
我猜如上所述,您正在寻找的组件不是 GameObject 类型。
如果您希望变量 GameObject myCube 指向 Cubey,您可以这样做:
GameObject myCube;
void Start(){
// Lets say you have a script attached called Cubey.cs, this solution takes a bit of time to compute.
myCube = GameObject.FindObjectOfType<Cubey>();
}
// This is a usually a better approach, You need to attach cubey through the inspector for this to work.
public GameObject myCube;
希望对遇到同样问题的人有所帮助。