Files
project-reset/Assets/Scripts/Units/UnitAnimation.cs
2025-10-20 13:47:16 -04:00

44 lines
1.4 KiB
C#

using System;
using UnityEngine;
namespace Reset.Units{
public class UnitAnimation : UnitComponent{
public Animator modelAnimator;
// Temporary
private float inputMagnitude;
void Start(){
}
void Update(){
try {
// Temporary
inputMagnitude = Mathf.MoveTowards(inputMagnitude, GetComponent<PlayerControls>().rawMoveInput.magnitude * 2f, 6f * Time.deltaTime);
modelAnimator.SetFloat("Move Direction X", Unit.Movement.GetResolvedDirectionLocal().x * inputMagnitude);
modelAnimator.SetFloat("Move Direction Y", Unit.Movement.GetResolvedDirectionLocal().y * inputMagnitude);
} catch (Exception e) {
Debug.LogError($"Failed in setting X and Y move direction floats: {e.Message}");
}
}
public void SendTriggerToAnimator(string trigger){
if (!modelAnimator) {
Debug.LogError($"There is no animator set to recieve the trigger '{trigger}' on unit {name}.", gameObject);
return;
}
try {
modelAnimator.SetTrigger(trigger);
}
catch (Exception e)
{
Debug.LogError($"Failed to send trigger to Animator: {e.Message}");
}
}
}
}