24 lines
703 B
C#
24 lines
703 B
C#
using KinematicCharacterController;
|
|
using UnityEngine;
|
|
|
|
namespace Code.Gameplay.Player
|
|
{
|
|
public class PlayerAnimator : MonoBehaviour
|
|
{
|
|
private static readonly int Velocity = Animator.StringToHash("Velocity");
|
|
|
|
private Animator _playerAnimator;
|
|
public void SetAnimator(Animator animator) => _playerAnimator = animator;
|
|
[SerializeField] private KinematicCharacterMotor kinematicCharacterMotor;
|
|
|
|
private void SetVelocity(float velocity)
|
|
{
|
|
_playerAnimator.SetFloat(Velocity, velocity);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
SetVelocity(kinematicCharacterMotor.Velocity.magnitude);
|
|
}
|
|
}
|
|
} |