「Unity/GameObject」の版間の差分
ナビゲーションに移動
検索に移動
| 18行目: | 18行目: | ||
public void AllUnderObject(GameObject obj) | public void AllUnderObject(GameObject obj) | ||
{ | { | ||
// ここで処理 | |||
Transform transforms = obj.GetComponentInChildren<Transform>(); | Transform transforms = obj.GetComponentInChildren<Transform>(); | ||
if (transforms.childCount > 0) | if (transforms.childCount > 0) | ||
2021年11月24日 (水) 03:06時点における版
子供のオブジェクト取得
GameObject child = obj.transform.Find("Child1Image").gameObject;
子供のオブジェクト一覧取得
Transform transforms = obj.GetComponentInChildren<Transform>();
if (transforms.childCount == 0) {
return;
}
foreach (Transform transform in transforms)
{
GameObject body = transform.gameObject;
Debug.Log("body.name=" + body.name);
}
配下のオブジェクトすべて取得
public void AllUnderObject(GameObject obj)
{
// ここで処理
Transform transforms = obj.GetComponentInChildren<Transform>();
if (transforms.childCount > 0)
{
foreach (Transform transform in transforms)
{
AllUnderObject(transform.gameObject); // 再帰処理
}
}
}
参考:http://sonnahiga.blog.fc2.com/blog-entry-18.html
非アクティブへ
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/オブジェクト操作 [ショートカット]