📌 Leerdoelen

🔍 2. Wat is een property?

➕ Standaard veld:

public int health;

✅ Property met private backing field:

private int health;

public int Health
{
    get { return health; }
    set { health = Mathf.Clamp(value, 0, 100); }

⚡ Automatische property:

public int Damage { get; set; }

Voordeel: Korter, goed voor simpele data (zonder logica)


🧠 3. Voorbeeld: Property in Unity context

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;
    }

🧩 4. Singleton met property

🔁 Oude manier (met Awake() en public veld):

public class GameManager : MonoBehaviour
{
    public static GameManager instance;

    void Awake()
    {
        if (instance == null)
        {
            instance = this;
            DontDestroyOnLoad(gameObject);
        }
        else
        {
            Destroy(gameObject);
        }
    }
}