Which code sample uses C# properties for creating the health functionality?
public class Health : MonoBehavior { private float HealthPoints = 100f; public float GetHealth() { return HealthPoints; } public void SetHealth(float Change) { HealthPoints += Change; if (HealthPoints <= 0) Destroy(gameObject); } }
public class Health : MonoBehavior { public UnityEvent OnHealthChanged; private float HealthPoints = 100f; public void SetHealth(float Change) { HealthPoints += Change; OnHealthChanged.Invoke(); } public void Die() { Destroy(gameObject); } }
public class Health : MonoBehavior { public float HealthPoints { get { return _healthpoints; } set { _healthpoints = value; if(_healthpoints <= 0 ) { Destroy(gameObjects); } } } private float _healthpoints = 100f; }
public class Health : MonoBehaviour { public float HealthPoints = 100f; private void Update() { if (HealthPoints <- 0) Destroy(gameObject); } }
get and set are the clear indicators that a C# property is being used.
get
set