I made this script so when my player hits the object it gets pushed up in the air, and after some time it then destroys itself.
I made a custom function called despawn, but when i call it, it ignores the WaitForSecond.
Why does it do that, and how do i fix it?
#pragma strict
var addForce = 0;
function Start () {
}
function Update () {
}
function OnCollisionEnter (col : Collision)
{
if(col.gameObject.tag == "Player")
{
gameObject.GetComponent(Rigidbody).isKinematic = false;
rigidbody.AddForce (0, addForce, 500);
Despawn ();
}
}
function Despawn () {
WaitForSeconds (10);
Destroy (gameObject);
}