Question about Destroying gameObjects

private void Die()
{
Destroy(gameObject);
GameObject explosion = Instantiate(particleExplosion, transform.position, Quaternion.identity) as GameObject;
Destroy(explosion,1f);

}

What i dont understand here if we run this method my logic says Destroy(gameObject);
this means deletes everything including the script too.If the script is destroyed how can we run the second line
GameObject explosion = Instantiate(particleExplosion, transform.position, Quaternion.identity) as GameObject;

this should be deleted because we destroyed the gameObject.

Thank you.

1 Like

Hi Shaktillar,

You are right about the purpose/task of the Destroy method. However, the Destroy method does not destroy everything immediately but rather near the end of the frame. The other lines have enough time to be executed.

Is this what you wanted to know?


See also:

1 Like

Ahh go it.Thank you :wink:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms