Prefabからオブジェクト生成

public GameObject cube;

public変数でgameObjectを宣言すると、
Inspectorのscriptのcomponent内に、GameObjectの参照ができるので、
そこに、Assets内に作っているPrefabをドラッグ&ドロップして登録する


float x = Random.Range(0.0f, 2.0f);
float y = Random.Range(0.0f, 2.0f);
float z = Random.Range(0.0f, 2.0f);

Instantiate(cube, new Vector3(x, y, z), Quaternion.identity);
第1引数 Prefab内のオブジェクト名
第2引数 位置
第3引数 角度
最終更新:2015年04月01日 23:34