as the tittle says haha
right now i have:
var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
but i want it to create my prefab called “tree”
as the tittle says haha
right now i have:
var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
but i want it to create my prefab called “tree”
There doesn’t seem to be a straight forward way to create a prefab dynamically by name but here are two methods that may solve your problem:
public MyPrefab prefab; // requires user to drag prefab into variable using the inspector
MyPrefab newPrefab = Instantiate(prefab, transform.position, transform.rotation) as MyPrefab;
or
MyPrefab prefab = Instantiate( Resources.LoadAssetAtPath("Assets/Prefabs/myPrefab.prefab", typeof(MyPrefab)) ) as MyPrefab;
I haven’t tested the second option but it should work.