Prefabの中で、別のPrefabを使う

GameObject b_Prefab = (GameObject)Resources.Load("BulletPrefab");
objects[j] = GameObject.Instantiate(b_Prefab, Vector3.zero, Quaternion.identity) as GameObject;

AssetsにResourcesというフォルダを作って、
そのフォルダ内にPrefabを置く。
Resources.Loadで取得できる

通常のGameObjectであれば、public変数にInspectorからPrefabを登録すれば
Instantiateできるが、
Prefab内でPrefabを使うには、Inspectorで事前に登録ができないので、
動的生成Prefabの場合は、上記のように、Resources.Loadを使うとできる

タグ:

unity
最終更新:2015年04月01日 23:30