Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Mob : MonoBehaviour
- {
- public MobInfo info;
- private Animator animator;
- private Health health;
- private AnimatorStateInfo currentStateInfo;
- private int idleHash;
- void Awake()
- {
- animator = GetComponent<Animator>();
- idleHash = Animator.StringToHash("Base Layer.IDLE");
- }
- void Start()
- {
- health = GetComponent<Health>();
- }
- public void Delete()
- {
- StartCoroutine(delete());
- }
- IEnumerator delete()
- {
- animator.SetBool("run", false);
- animator.SetBool("walk", false);
- while (true)
- {
- currentStateInfo = animator.GetCurrentAnimatorStateInfo(0);
- if (currentStateInfo.nameHash == idleHash)
- {
- animator.SetTrigger("die");
- yield return new WaitForSeconds(1.4f);
- Destroy(gameObject);
- break;
- }
- else
- {
- yield return new WaitForEndOfFrame();
- }
- }
- }
- public void SetState(MobInfo info)
- {
- info.position.y -= 2.45f;
- transform.position = info.position.GetVector3();
- transform.LookAt(transform.position + info.moveDirection.GetVector3());
- health.SetHealth(info.currentHP, info.maxHP);
- switch (info.state)
- {
- case StatesOfMob.IDLE:
- animator.SetBool("run", false);
- animator.SetBool("walk", false);
- break;
- case StatesOfMob.WALK:
- animator.SetBool("run", false);
- animator.SetBool("walk", true);
- break;
- case StatesOfMob.RUN:
- animator.SetBool("run", true);
- animator.SetBool("walk", false);
- break;
- case StatesOfMob.ATTACK:
- animator.SetTrigger("attack");
- animator.SetBool("run", false);
- animator.SetBool("walk", false);
- break;
- }
- }
- void OnDestroy()
- {
- Destroy(health.gameObject);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement