Batch 1 - Scripts
This commit is contained in:
37
Assets/New Lowpoly Models/Scripts/Player/Stamina.cs
Normal file
37
Assets/New Lowpoly Models/Scripts/Player/Stamina.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user