Skip to content

Instantly share code, notes, and snippets.

@unity3dcollege
Created December 29, 2016 06:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unity3dcollege/20fc42886d3ab17d37aa590391633ad2 to your computer and use it in GitHub Desktop.
Save unity3dcollege/20fc42886d3ab17d37aa590391633ad2 to your computer and use it in GitHub Desktop.
using System;
using UnityEngine;
public class NPC : MonoBehaviour
{
public event Action OnNPCDied = delegate { };
internal void TakeDamage(int amount)
{
GetComponent<Health>().TakeDamage(amount);
if (GetComponent<Health>().CurrentHpPctent <= 0)
Die();
}
private void Die()
{
OnNPCDied();
GameObject.Destroy(this.gameObject);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment