37 lines
843 B
C#
37 lines
843 B
C#
using System;
|
|
using UnityEngine;
|
|
|
|
public class Stamina : MonoBehaviour
|
|
{
|
|
public float currentStamina;
|
|
public float maxStamina = 100f;
|
|
|
|
public event Action<float, float> OnStaminaChanged;
|
|
|
|
void Start()
|
|
{
|
|
currentStamina = maxStamina;
|
|
OnStaminaChanged?.Invoke(currentStamina, maxStamina);
|
|
}
|
|
|
|
public bool UseStamina(float amount)
|
|
{
|
|
if (currentStamina <= 0f)
|
|
return false;
|
|
|
|
currentStamina -= amount;
|
|
|
|
if (currentStamina < 0f)
|
|
currentStamina = 0f;
|
|
|
|
OnStaminaChanged?.Invoke(currentStamina, maxStamina);
|
|
|
|
return currentStamina > 0f;
|
|
}
|
|
|
|
public void RecoverStamina(float amount)
|
|
{
|
|
currentStamina = Mathf.Clamp(currentStamina + amount, 0, maxStamina);
|
|
OnStaminaChanged?.Invoke(currentStamina, maxStamina);
|
|
}
|
|
} |