Advertisement
Guest User

Untitled

a guest
May 28th, 2015
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.14 KB | None | 0 0
  1. public class Mob : MonoBehaviour
  2. {
  3.     public MobInfo info;
  4.     private Animator animator;
  5.     private Health health;
  6.     private AnimatorStateInfo currentStateInfo;
  7.     private int idleHash;
  8.  
  9.     void Awake()
  10.     {
  11.         animator = GetComponent<Animator>();
  12.         idleHash = Animator.StringToHash("Base Layer.IDLE");
  13.     }
  14.  
  15.     void Start()
  16.     {
  17.         health = GetComponent<Health>();
  18.     }
  19.  
  20.     public void Delete()
  21.     {
  22.         StartCoroutine(delete());
  23.     }
  24.  
  25.     IEnumerator delete()
  26.     {
  27.         animator.SetBool("run", false);
  28.         animator.SetBool("walk", false);
  29.         while (true)
  30.         {
  31.             currentStateInfo = animator.GetCurrentAnimatorStateInfo(0);
  32.             if (currentStateInfo.nameHash == idleHash)
  33.             {
  34.                 animator.SetTrigger("die");
  35.                 yield return new WaitForSeconds(1.4f);
  36.                 Destroy(gameObject);
  37.                 break;
  38.             }
  39.             else
  40.             {
  41.                 yield return new WaitForEndOfFrame();
  42.             }
  43.         }
  44.     }
  45.  
  46.     public void SetState(MobInfo info)
  47.     {
  48.         info.position.y -= 2.45f;
  49.         transform.position = info.position.GetVector3();
  50.         transform.LookAt(transform.position + info.moveDirection.GetVector3());
  51.         health.SetHealth(info.currentHP, info.maxHP);
  52.  
  53.         switch (info.state)
  54.         {
  55.             case StatesOfMob.IDLE:
  56.                 animator.SetBool("run", false);
  57.                 animator.SetBool("walk", false);
  58.                 break;
  59.             case StatesOfMob.WALK:
  60.                 animator.SetBool("run", false);
  61.                 animator.SetBool("walk", true);
  62.                 break;
  63.             case StatesOfMob.RUN:
  64.                 animator.SetBool("run", true);
  65.                 animator.SetBool("walk", false);
  66.                 break;
  67.             case StatesOfMob.ATTACK:
  68.                 animator.SetTrigger("attack");
  69.                 animator.SetBool("run", false);
  70.                 animator.SetBool("walk", false);
  71.                 break;
  72.         }
  73.     }
  74.  
  75.     void OnDestroy()
  76.     {
  77.         Destroy(health.gameObject);
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement