簡體   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