Wait?

Whats the code for wait time?
I want to throw a grenade and when it collides with something it explodes a couple of seconds after.

Here is the code I have now:
var explosion : GameObject;

function OnCollisionEnter( collision : Collision)
{
var contact : ContactPoint = collision.contacts[0];
var rotation = Quaternion.FromToRotation(Vector3.up, contact.normal );
var instantiatedExplosion : GameObject = Instantiate(
explosion, contact.point, rotation );
Destroy( gameObject );
}

Also in another attached script:

function Update ()
{
transform.Rotate(5, 0, 5);
}

And attached to the invisible sphere I named the launcher:

var projectile : Rigidbody;
var speed = 20;

function Update ()
{
if( Input.GetButtonDown( “Fire1” ) )
{
var instantiatedProjectile : Rigidbody = Instantiate(projectile, transform.position, transform.rotation );

instantiatedProjectile.velocity =
transform.TransformDirection( Vector3( 0, 0, speed ) );

Physics.IgnoreCollision( instantiatedProjectile. collider,
transform.root.collider );

}
}

You can either set the destruction time by
Destroy(Object, timeInSeconds).

or you can do
yield waitForSeconds(seconds)
and then call
Destroy(object)
or call a function that does that.

Cheers

Im also trying to make the explosion effect come when it disappears as well.

Use Invoke. So your script would add:

var contactPoint : Vector3;
var contactNormal : Quaternion;

function OnCollisionEnter (collision : Collision)
{
    contactPoint = collision.contacts[0].point;
    contactNormal = Quaternion.FromToRotation (Vector3.up, collision.contacts[0].normal);
    Invoke ("Explode", explosionDelay);
}

function Explode ()
{
    Instantiate(explosion, contactPoint, contactNormal);
    Destroy( gameObject );
}

Worked thanks!

Destroy in seconds, I was looking for that myself! Thanks! :slight_smile: