Hello! I can’t seem to figure out how to destroy an object once it was instantiated!?
I am creating a custom animation called white puff which shows up once i shoot another game object.
but then i want to be able to destroy the white puff after a certain time (once the animation is done playing)
In one of the tutorials this yield and Destroy code seemed to work but it was used in an update function…
any help on what is the proper way to set this up?
=============================================
var whitePuff : GameObject;
var sound : AudioClip;
function OnCollisionEnter(collision : Collision)
{
if (collision.gameObject.tag == “bullet”)
{
AudioSource.PlayClipAtPoint(sound, transform.position);
Destroy(gameObject); //Destroy
// Instantiate the game object at the same position we are at
var clonePuff:GameObject = Instantiate(whitePuff, transform.position, transform.rotation);
yield WaitForSeconds(2);
Destroy(clonePuff.GameObject);
}
}