gather-and-defend/Assets/Scripts/AnimationEntity.cs
2023-07-07 19:15:56 -04:00

57 lines
1.1 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AnimationEntity : MonoBehaviour
{
private Animator _animatorEntity;
private bool _doSomething = false;
private bool _isDead = false;
void Start()
{
_animatorEntity = GetComponentInChildren<Animator>();
}
void Update()
{
if (_doSomething && _animatorEntity.GetCurrentAnimatorStateInfo(0).normalizedTime >= 1f)
{
PlayIdleAnim();
_doSomething = false;
}
}
public void PlayIdleAnim()
{
if(!_isDead) {
_animatorEntity.Play("idle", 0, 0f);
}
}
public void PlayWalkAnim()
{
if(!_isDead) {
_animatorEntity.Play("walk", 0, 0f);
}
}
public void PlayAttackAnim()
{
if(!_isDead) {
_animatorEntity.Play("attack", 0, 0f);
_doSomething = true;
}
}
public void PlayDieAnim()
{
_animatorEntity.Play("die", 0, 0f);
_doSomething = true;
_isDead = true;
}
}