Instantiate object (37973)

I’m stucked with a next problem: I have a prefab “TestObject” and I need to instantiate it in runtime (it doesnt exist in the game initially). From all examples I had seen there are only one example given to everyone:

public GameObject prefab;

//...
Instantiate(prefab, new Vector3(x,y,z), Quaternion.identity) as GameObject;
//...

But I don’t know what prefab will be created so I can’t assign any value to it. Basically what I would like to do is create predefined cube and after say to it: “you gonna use model X”. Is that possible?

You need:

var prefab : Transform;

outside your function, and drag what you want instantiating onto it in the inspector, like Eric said.

If you want a cube to “change into” your prefab, you’d have to destroy the cube (Destroy (gameObject); ) and use the transform and rotation of said cube in the instantiate Vector3 and rotation.

Hope I understood this right, and that it helps! :slight_smile: