「Unity/GameObject」の版間の差分

提供: 初心者エンジニアの簡易メモ
ナビゲーションに移動 検索に移動
編集の要約なし
10行目: 10行目:


==ボタンなどが貼り付けられてるクラスからGameObject取得==
==ボタンなどが貼り付けられてるクラスからGameObject取得==
<pre>
GameObject btnObj =GameObject.Find("Button");
GameObject btnObj =GameObject.Find("Button");
Button btn = btnObj.GetComponent<Button>();
Button btn = btnObj.GetComponent<Button>();
GameObject obj = btn.gameObject;
GameObject obj = btn.gameObject;
</pre>

2021年10月4日 (月) 10:07時点における版

子供のオブジェクト取得

GameObject child = obj.transform.Find("Child1Image").gameObject;

非アクティブへ

obj.SetActive(true);

オブジェクトより手前に

Transform trans1 = GameObject.Find("Object1").transform;
trans1.SetSiblingIndex(0);

ボタンなどが貼り付けられてるクラスからGameObject取得

GameObject btnObj =GameObject.Find("Button");
Button btn = btnObj.GetComponent<Button>();
GameObject obj = btn.gameObject;