繁体   English   中英

查找具有名称和gameObject内的组件的gameObject?

[英]Find a gameObject with name and a component inside the gameObject?

我想通过其名称找到一个gameObject,然后获取该gameObject的组件。 例如:

GameObject Go;
InputField GoInput;

void Start()
{
  Go = GameObject.Find("TextField"); //which I know
  GoInput = GameObject.Find("TextField").GetComponent<InputField>(); //is this proper because it does not work
}

编辑:用上面的代码本身解决了它。 在“文本”和“字段”之间有一个空格。

尝试:

InputField GoInput = GameObject.Find("TextField").GetComponent("InputField") as InputField;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM