34 lines
1.0 KiB
C#
34 lines
1.0 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;
|
|
private Animator _animator;
|
|
|
|
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);
|
|
|
|
}
|
|
}
|
|
} |