34 lines
1.1 KiB
C#
34 lines
1.1 KiB
C#
using System;
|
|
using KinematicCharacterController;
|
|
using Reflex.Attributes;
|
|
using UnityEngine;
|
|
|
|
namespace Code.OfficeGame.Player
|
|
{
|
|
public class PlayerAnimator : MonoBehaviour
|
|
{
|
|
private static readonly int VelocityForward = Animator.StringToHash("VelocityForward");
|
|
private static readonly int VelocityRight = Animator.StringToHash("VelocityRight");
|
|
|
|
private KinematicCharacterMotor _motor;
|
|
public Animator Animator { get; private set; }
|
|
|
|
private void Awake()
|
|
{
|
|
_motor = GetComponent<KinematicCharacterMotor>();
|
|
Animator = GetComponentInChildren<Animator>();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
var forwardVelocity =
|
|
Vector3.Project(_motor.Velocity, transform.right).magnitude;
|
|
Animator.SetFloat(VelocityForward, forwardVelocity);
|
|
|
|
var rightVelocity =
|
|
Vector3.Project(_motor.Velocity, transform.forward).magnitude;
|
|
Animator.SetFloat(VelocityRight, rightVelocity);
|
|
|
|
}
|
|
}
|
|
} |