Files
Test-Multiplayer/Assets/Scripts/AnimationStateController.cs
pelpanagiotis 329b7d3183 First Commit
2025-12-21 18:31:02 +02:00

45 lines
999 B
C#

using UnityEngine;
using UnityEngine.InputSystem;
public class AnimationStateController : MonoBehaviour
{
Animator animator;
float velocity = 0.0f;
public float acceleration = 0.3f;
public float deceleration = 0.5f;
int VelocityHash;
void Start()
{
animator = GetComponent<Animator>();
VelocityHash = Animator.StringToHash("Blend");
}
void Update()
{
var keyboard = Keyboard.current;
if (keyboard == null) return;
bool forwardPressed = keyboard.wKey.isPressed;
bool runPressed = keyboard.leftShiftKey.isPressed;
if (forwardPressed)
{
velocity += Time.deltaTime * acceleration;
}
if (!forwardPressed && velocity > 0.0f)
{
velocity -= Time.deltaTime * deceleration;
}
if (!forwardPressed && velocity < 0.0f)
{
velocity = 0.0f;
}
animator.SetFloat(VelocityHash, velocity);
}
}