I have a script that handles the player lives
health1 is an image of one heart indicates that the player has one life left
health2 is an image of two hearts indicates that the player has two lives left and health3 is an image of three hearts ( a full health)
and finished_panel is a panel that tells the player that the game is over and displays a “new game” button. a script that reload the scene is attached to this button
the problem is when the button is clicked, the scene is reloaded but it keeps giving a null reference for health1,health2,health3 and finished panel.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class LivesControl : MonoBehaviour {
public GameObject health1;
public GameObject health2;
public GameObject health3;
public static int LIVES=3;
public GameObject finished_panel;
void Start(){
health1.SetActive (false);
health2.SetActive (false);
health3.SetActive (false);
finished_panel.SetActive (false);
}
// Update is called once per frame
void Update () {
switch (LIVES)
{
case 3:
health3.SetActive (true);
break;
case 2:
health3.SetActive (false);
health2.SetActive (true);
break;
case 1:
health2.SetActive (false);
health1.SetActive (true);
break;
case 0:
health1.SetActive(false);
finished_panel.SetActive (true);
Time.timeScale = 0;
break;
}
}
}