GameObject.Getcomponent<"組件名稱">(); 返回 組件名稱類型的返回值,可以認爲是該組件對象的索引。
例子:
private Transform m_Transform;//定義一個私有的Transform 組件類型的變量。
m_Transform = GameObject.Find("Play").GetComponent<Transform>("XXX");// XXX參數是字符串, 查找一個叫Play的遊戲對象,查找對象的Transform組件然後返回Transform類型的變量。
例子:
private GameObject m_GameObject;//創建一個私有的GameObject類型的變量。
m_GameObject = GameObject.Find("Play"); //查找一個遊戲中名爲Play的遊戲對象,返回一個GameObject類型的變量 存放在m_GameObject。
FindGameObjectsWithTag(string) 通過遊戲對象標籤查找遊戲中所有該標籤的遊戲對象,返回一個GameObject數組類型的變量。
例子:
private GameObject[] m_object;//定義一個GameObject類型的數組 m_object.
m_object = GameObject.FindGameObjectsWithTag("Play");//查找所有標籤是Play的遊戲對象,返回GameObject類型數組存放在m_object。
Instantiate(Object,Vector3,Quaternion);實例化[克隆]遊戲物體 。
例子: