「Unity/GameObject」の版間の差分

提供: 初心者エンジニアの簡易メモ
ナビゲーションに移動 検索に移動
1行目: 1行目:
==子供のオブジェクト取得==
==子供のオブジェクト取得==
  GameObject child = obj.transform.Find("Child1Image").gameObject;
  GameObject child = obj.transform.Find("Child1Image").gameObject;
==子供のオブジェクト一覧取得==
<pre>
Transform transforms  = obj.GetComponentInChildren<Transform>();
if (transforms.childCount == 0) {
    return;
}
</pre>


==非アクティブへ==
==非アクティブへ==

2021年11月23日 (火) 20:12時点における版

子供のオブジェクト取得

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

子供のオブジェクト一覧取得

Transform transforms  = obj.GetComponentInChildren<Transform>();
if (transforms.childCount == 0) {
    return;
}

非アクティブへ

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;

こちらも参照

Unity/Csharp/オブジェクト操作 [ショートカット]