2014年5月30日金曜日

オブジェクトのコンポーネント(Script)を取得 [Unity C#]

スクリプト名「SampleClass」
SampleClassの変数宣言
public string str = "";

//親オブジェクトを取得
GameObject objParent = this.transform.parent.gameObject;
//親オブジェクトのコンポーネント(Script)を取得
SampleClass SC = objParent.GetComponent<SampleClass>();
SC.str = "AAA";



2014年5月14日水曜日

子オブジェクトの取得 [Unity C#]

//オブジェクト取得
GameObject Play1;
Play1 = GameObject.Find("Character1");
Play1.transform.localPosition = new Vector3(0 , 0 , 0);

//子オブジェクト取得
GameObject Play2;
Play2 = GameObject.FindChild("Character").gameObject;
Play2.transform.localPosition = new Vector3(0 , 0 , 0);


など