In my Asteroids game, when the ship collides with the asteroid, it explodes and dies, but it doesn't reload the scene. Please help. Code (CSharp): using UnityEngine; using System.Collections; public class ShipControls : MonoBehaviour { public ParticleSystem explodeFx; void OnCollisionEnter2D (Collision2D collision) { if (collision.gameObject.tag == "Asteroid Tag") { Invoke ("reload", 2.0f); ParticleSystem fx = Instantiate (explodeFx, transform.position, Quaternion.identity) as ParticleSystem; Destroy (fx.gameObject, fx.duration + fx.startLifetime); Destroy (gameObject); } } void reload() { Application.LoadLevel(Application.loadedLevel); } }
Invoke stays alive within this particular MonoBehaviour instance, just like e.g. coroutines. You are destroying the game object and with the game object, you are destroying this MonoBehaviour instance in which you started the invoke. As invoke is part of the MonoBehaviour instance, you are destroying the invoke call as well. You have to make sure that invoke is called in a MonoBehaviour instance that is not being destroyed.