public int health;
private int health;
public int Health
{
get { return health; }
set { health = Mathf.Clamp(value, 0, 100); }
public int Damage { get; set; }
Voordeel: Korter, goed voor simpele data (zonder logica)
public class Player : MonoBehaviour
{
private int health;
public int Health
{
get { return health; }
set
{
health = Mathf.Clamp(value, 0, 100);
Debug.Log("Health is nu: " + health);
}
}
void Start()
{
Health = 120;
}
Awake() en public veld):public class GameManager : MonoBehaviour
{
public static GameManager instance;
void Awake()
{
if (instance == null)
{
instance = this;
DontDestroyOnLoad(gameObject);
}
else
{
Destroy(gameObject);
}
}
}