Hi, I am making a class which it is supposed to load every time I load a level, but the methods Start and Awake is only loaded the first time this level is loaded, and as a result, the number of lives is not displayed when the level is restarted.
Here is the important part of my class:
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using System.Collections;
//TODO: Cuando se recarga el nivel no fucniona bien! No vuelve a pasar por Star ni por Awake!
public class LevelManager : MonoBehaviour {
public Text timeText;
public Text scoreText;
public Text lifeText;
public Slider slider;
public static LevelManager levelManager; //Singleton
public int score = 0;
private Animator animator;
public float seconds = 0;
float minutes = 0;
int stars = 0;
void Awake(){
if (levelManager == null) { //Singleton
levelManager = this;
} else if (levelManager != this) {
Destroy (gameObject);
}
}
void Start(){
Debug.Log ("Start");
GameControl.Load ();
animator = GetComponent<Animator> ();
lifeText.text = "x" + GameControl.lives;
}
}
To load my level I simply do:
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
public class LoadSceneOnClick : MonoBehaviour {
public void LoadByIndex(int sceneIndex)
{
SceneManager.LoadScene (sceneIndex);
}
}
Anyone know how to fix this? Is this maybe a bug?
Thanks!