Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Hero : MonoBehaviour {
- [SerializeField]
- private float _health; // This will still be available in the inspector
- public void TakeDamage(float dmg) {
- _health -= dmg;
- if(_health <= 0) Die();
- }
- private void Die() {
- // Make gurgling noises and die dramatically
- }
- }
- public class Enemy : MonoBehaviour {
- private Hero _hero;
- void Start() {
- _hero = FindObjectOfType<Hero>();
- _hero.TakeDamage(2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement