Hello I’m pretty new to coding in unity but I’ve created a first person controller and I am trying to implement a stamina system. Regardless if the stamina has hit 0 or not my player remains in sprint and keeps the additional move speed from sprinting until I release the sprint key. If anyone could help me with this problem that would be great. This is almost my first time posting here so hopefully everything looks correct.
In your PlayerMovement script, you don’t seem to be checking if you have the stamina to sprint or continue to sprint. Right now your if check just says that if I’m holding down the sprint button and I’m grounded, keep my movement speed set to the sprinting speed.
You just need a way to check against your stamina, or setting a bool that is controlled by PlayerStats like “canSprint”.
Also, instead of bools for isSprinting, isCroached, etc. You might consider an enum to track what state the user is in.
For future reference posting code with codes tags is the preferred method to getting someone to help out. (since it’s your first time posting)
Thank you, I actually got my character to stop sprinting when stamina hit 0 by checking for stamina in my PlayerMovement script. I am now experiencing a weird bug where if I just hold down the “sprint button” as soon as my stamina begins to regen to only 1 I get full sprint speed again. So now my goal is to put a delay between having 0 stamina and then regenerating the stamina. Should I use coroutines for that?


