I added this code to replenish and use stamina but it wont work and when i play the game unity seems to crash. i dont know if its unity or an infinite loop because it just freezes up before i can test the game.
i will link my code below but the important part is the Sprint method.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameInput : MonoBehaviour
{
public float moveSpeed;
public float clockwise = 50f;
public float sprint = 2;
public float sprintCoolDown = 5;
public bool isSprinting;
Player player = new Player();
[SerializeField] private StaminaBar staminaBar;
public float maxStamina = 100;
public float currentStamina;
public void Sprint()
{
currentStamina = maxStamina;
staminaBar.SetMaxStamina(maxStamina);
bool hasStamina = true;
if(currentStamina <= 0)
{
hasStamina = false;
}
while (currentStamina > 0)
{
moveSpeed = moveSpeed * sprint;
staminaBar.UseStamina(1);
isSprinting = true;
}
if (hasStamina == false || isSprinting == false)
{
WaitSeconds();
while (currentStamina < 50 || isSprinting == false)
{
currentStamina = currentStamina +1;
}
hasStamina = true;
}
}
IEnumerator WaitSeconds()
{
yield return new WaitForSeconds(sprintCoolDown);
}
}```