Added sprinting
parent
703f8614d9
commit
c8541d23b6
@ -0,0 +1,43 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class StaminaManager : MonoBehaviour
|
||||||
|
{
|
||||||
|
[SerializeField] private float maxStamina = 100f;
|
||||||
|
[SerializeField] private float staminaRegenRate = 10f;
|
||||||
|
[SerializeField] private float staminaRegenDelay = 1f;
|
||||||
|
|
||||||
|
private float currentStamina;
|
||||||
|
private float staminaRegenTimer;
|
||||||
|
|
||||||
|
public float CurrentStamina => currentStamina;
|
||||||
|
public float MaxStamina => maxStamina;
|
||||||
|
|
||||||
|
private void Start()
|
||||||
|
{
|
||||||
|
currentStamina = maxStamina;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Update()
|
||||||
|
{
|
||||||
|
if (staminaRegenTimer > 0)
|
||||||
|
{
|
||||||
|
staminaRegenTimer -= Time.deltaTime;
|
||||||
|
}
|
||||||
|
else if (currentStamina < maxStamina)
|
||||||
|
{
|
||||||
|
currentStamina += staminaRegenRate * Time.deltaTime;
|
||||||
|
currentStamina = Mathf.Min(currentStamina, maxStamina);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool TryConsume(float amount)
|
||||||
|
{
|
||||||
|
if (currentStamina >= amount)
|
||||||
|
{
|
||||||
|
currentStamina -= amount;
|
||||||
|
staminaRegenTimer = staminaRegenDelay;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: dfa72a58317173e498650d65775537d5
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
Loading…
Reference in New Issue