TurnBasedStrategyCourse/Assets/Scripts/UnitAnimator.cs

25 lines
967 B
C#

using System;
using Actions;
using UnityEngine;
public class UnitAnimator : MonoBehaviour {
[SerializeField] private Animator animator;
private static readonly int isWalking = Animator.StringToHash("IsWalking");
private static readonly int shoot = Animator.StringToHash("Shoot");
private void Awake() {
if (TryGetComponent(out MoveAction moveAction)) {
moveAction.OnStartMoving += MoveAction_OnStartMoving;
moveAction.OnStopMoving += MoveAction_OnStopMoving;
}
if (TryGetComponent(out ShootAction shootAction)) {
shootAction.OnShoot += ShootAction_OnShoot;
}
}
private void MoveAction_OnStartMoving(object sender, EventArgs e) => animator.SetBool(isWalking, true);
private void MoveAction_OnStopMoving(object sender, EventArgs e) => animator.SetBool(isWalking, false);
private void ShootAction_OnShoot(object sender, EventArgs e) => animator.SetTrigger(shoot);
}