Hi guys, I currently have a script called “Player_Controller” which is attached to a player. And then I have this segment of code;
void Update () {
if (gameObject.activeSelf == false) {
Application.LoadLevel("game_over");
}
}
void OnTriggerEnter2D(Collider2D other) {
if (other.CompareTag ("enemy") == true) {
life -= 100;
health_bar.value = life;
Destroy(other.gameObject, 0.8f);
if (life <= 0) {
audio.PlayOneShot(ExplosionSFX);
Instantiate(explosionPrefab , transform.position, Quaternion.identity);
Destroy(gameObject, 1.5f);
}
}
}
Basically, what I’m trying to do is when my player dies and the player object gets destroyed, it will load the “game_over” scene. As you can see from here, I have that segment under the Update function but it does not get called at all. I had also included a debug log right below the Application.LoadLevel and it doesn’t show.
If you destroy the GameObject that contains this script then update is no longer called. Try using void OnDisable() or OnDestroy() instead of Update() if this is what you want.