67 lines
1.3 KiB
C#
67 lines
1.3 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;
|
|
private bool _isWalking = false;
|
|
|
|
void Start()
|
|
{
|
|
_animatorEntity = GetComponentInChildren<Animator>();
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
|
|
if (_doSomething && _animatorEntity.GetCurrentAnimatorStateInfo(0).normalizedTime >= 1f)
|
|
{
|
|
PlayIdleAnim();
|
|
_doSomething = false;
|
|
_isWalking = false;
|
|
}
|
|
}
|
|
|
|
public void PlayIdleAnim()
|
|
{
|
|
if(!_isDead) {
|
|
_animatorEntity.Play("idle", 0, 0f);
|
|
}
|
|
}
|
|
|
|
public void PlayWalkAnim()
|
|
{
|
|
if(!_isDead) {
|
|
_animatorEntity.Play("walk", 0, 0f);
|
|
_isWalking = true;
|
|
}
|
|
}
|
|
|
|
public void PlayAttackAnim()
|
|
{
|
|
if(!_isDead) {
|
|
_animatorEntity.Play("attack", 0, 0f);
|
|
_doSomething = true;
|
|
}
|
|
}
|
|
|
|
public void PlayDieAnim()
|
|
{
|
|
_animatorEntity.Play("die", 0, 0f);
|
|
_doSomething = true;
|
|
_isDead = true;
|
|
}
|
|
|
|
//SETTER GETTER
|
|
public bool IsWalking
|
|
{
|
|
get { return _isWalking; }
|
|
set { _isWalking = value; }
|
|
}
|
|
|
|
}
|