반응형
- 코드 작성
using UnityEngine;
public class StaminaEffect : MonoBehaviour
{
public float maxStamina = 100f;
public float currentStamina;
public float staminaDecayRate = 10f;
public float staminaRecoveryRate = 5f;
private bool isRecoveringStamina = false;
private void Start()
{
currentStamina = maxStamina;
}
private void Update()
{
if (!isRecoveringStamina)
{
currentStamina -= staminaDecayRate * Time.deltaTime;
if (currentStamina <= 0f)
{
OnStaminaDepleted();
}
}
else
{
currentStamina += staminaRecoveryRate * Time.deltaTime;
if (currentStamina >= maxStamina)
{
isRecoveringStamina = false;
}
}
}
public void StartStaminaRecovery()
{
isRecoveringStamina = true;
}
private void OnStaminaDepleted()
{
Debug.Log("Stamina depleted!");
}
}
반응형