Yield WaitForSeconds never finishes?

I’m having trouble with this section of code. The code words up to Debug.Log(“Power Up”) and then doesn’t go any further and I don’t get Debug.Log(“POWER DOWN”)

function OnCollisionExit(collision : Collision){

	   if (collision.collider.tag == "player") {
	   		Destroy (gameObject);
			Player.speed = 40;
			Debug.Log("POWER UP");
			yield WaitForSeconds (5);
			Player.speed = 25;
			Debug.Log("POWER DOWN");
		}
  }

You’ve destroyed the GameObject at the beginning. Therefore the coroutine will never execute after it yields and the object is really obliterated.

You probably want to hide it rather than destroy it at the top, then Destroy after the yield.

Hey ,

when you call the destroy(gameobject) you kill the gameobject with the script the power up is being called cause it waits till the end of the frame to delete the game object

function OnCollisionExit(collision : Collision){

   if (collision.collider.tag == "player") {
      
     Player.speed = 40;
     Debug.Log("POWER UP");
     yield WaitForSeconds (5);
     Player.speed = 25;
     Debug.Log("POWER DOWN");

Destroy (gameObject);
}
}

this will work