2014年6月11日水曜日

プレハブでインスタンス生成時に子オブジェクト一覧を取得する [Unity C#]

子オブジェクト一覧を取得する

int iCount = transform.childCount;

bool ansTop = false;
bool ansButtom = false;

string Top = "";
string Buttom = "";

void Start () {
for(int i=0; i<iCount; i++){
Transform child = transform.GetChild (i);
Debug.Log("ObjectName : " + child.name);

if (ansTop) {
Top = child.name;
Debug.Log("Top : " + Top);
ansTop = false;
} else if (ansButtom) {
Buttom = child.name;
Debug.Log("Buttom : " + Buttom);
ansButtom = false;
}
}
}




0 件のコメント:

コメントを投稿