I have a Script called Player.cs and inside of it there is a public class called PlayerStats with a health integer.
public class Player : Monobehaviour{
[System.Serializable]
public class PlayerStats
{
public int Health = 100;
}
}
and I also have a class Health UI called HealthUI.cs with a UItext
public class HealthUI : Monobehaviour
{
Text text;
private static int health;
private Player player
void Start()
{
text = GetComponent <Text> ();
player =(Player)GameObject.FindGameObjectWithTag("Player").
GetComponent(typeof(Player));
}
void Update()
{
health = player.playerStats.Health;
text.text = "Health" + health;
` `}
}
My problem is :
-
In Scene, the UI text (Health : 100) and subtracting my health works. But when my object is destroyed and spawns again, my HealthUI doesnt reset to 100 and stops to work.
-
How can I limit my health to 0 minimum number and 100 as maximum number?
Please help