Hey guys, I am working on a simple game and the life system is not working.
Player script :
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class Player : MonoBehaviour {
public Text livesText;
public int lives;
void Update ()
{
livesText.text = "Lives : " + lives;
}
void OnTriggerEnter (Collider other)
{
if (other.transform.tag == "Enemy")
{
Debug.Log ("You have " + lives + " lives");
SceneManager.LoadScene (SceneManager.GetActiveScene ().buildIndex);
}
}
I know the problem is, as Unity is just remebering my starting no. of lives and so it is just posting the no. of lives as 3. I tried to subtract in the OnCollisionEnter function. I tried many things but the problem remained the same. Please can anyone provide me the solution. I spent hours doing this but this is the last part of the game.
Thanks in advance.