canto/Assets/Scripts/Entity/SprintFeature.cs
2025-10-02 15:28:03 -04:00

48 lines
1.1 KiB
C#

using KitsuneCafe.Extension;
using R3;
using UnityAtoms.BaseAtoms;
using UnityEngine;
namespace KitsuneCafe.Entities
{
public class SprintFeature : MonoBehaviour
{
[SerializeField]
private Motor motor;
[SerializeField]
private BoolReference sprint;
[SerializeField]
private float adjustedMaxSpeed = 3f;
public float SprintSpeed => adjustedMaxSpeed;
public readonly ReactiveProperty<bool> IsSprinting = new(false);
private void Reset()
{
motor = GetComponent<Motor>();
}
private void Awake()
{
sprint.ObserveChange()
.Subscribe(Sprint)
.RegisterTo(destroyCancellationToken);
}
public void Sprint(bool shouldSprint = true)
{
if (shouldSprint)
{
motor.ChangeMaxSpeed(adjustedMaxSpeed);
}
else
{
motor.ResetMaxSpeed();
}
IsSprinting.Value = shouldSprint;
}
}
}