How to insert an object after Destroy(gameObject)

Hello, I was wondering for quite some time how to, after the destroy function is called, insert another game object. I’ve tried the Instantiate function but it doesn’t seem to work. Here is the script that I’m using:

function OnTriggerEnter(hit : Collider)    

So I was just wondering if it is at all possible to create another game object right after this function… and I would also like to know how to make the other object appear after the destroy is called, but in another script.

You can’t use any other calls after the destruction of the gameObject, because the script will also be destroyed along with the gameObject. If you want to do something after you have destroyed a gameObject, it’s as simple as not attaching the script to the object you want to destroy, but to an empty gameObject. :slight_smile:

Hope that was clear enough, Klep

var prefabOfYourObject : Transform; // here you drag the prefab in the inspector

var newObject = Instantiate(prefabOfYourObject, transform.position,Quaternion.identity);

var newObject means you want to declare a new variable and this variable will be given the information coming in Instantiate(1,2,3);

1= the prefab of the object you want to create

2= where you want to appear, in this case transform.position it is taking the position of the object the script is attached to. You can give any value as long as it is a Vector3(x,y,z).

3= The rotation of the object when created, Quaternion.identity means you want it to appear as the prefab is (more or less), Quaternion is pretty complicated and deals with complex number so… Here you could give any kind of other rotation there, if you want your guy upside down or else.