Unity Playmaker - Mouse Run Game -Drain and Fill Stamina Bar
In this mini Unity Playmaker - Mouse Run Game -Drain and Fill Stamina Bar tutorial, we will set up a stamina bar that will drain quickly when you are running fast and fill back up when you are jogging slow. (to Join my discord server add a comment and I'll reply with the latest invite code) ► Down
In the mouse run mini-series, the character can already sprint while the space bar is held. This tutorial adds the cost: a stamina bar that drains fast during the sprint, forces you back to a jog at zero, and slowly refills while jogging. It's a classic resource loop built from a UI slider, one float variable, and three Playmaker actions reused in two states.
Build the stamina slider
Add a UI Slider named stamina and delete its handle — this is a display, not a control. The slider's value is normalized, 0 to 1, which reads naturally as 0% to 100%. Make it about 200 wide, move it out of the middle of the screen, and set contrasting colors: a darker blue background with a brighter fill. One cleanup detail: with the handle gone, the fill area's RectTransform still reserves handle space, so the bar never looks quite full. Set the fill's left and right padding to match (5 and 5 here) and the fill reaches the ends properly. Rename the canvas ui in game.
Drain stamina in the fast run
In the game manager FSM, create a float variable called stamina preset to 1. In the fast run state, add a Float Operator: subtract 0.01 from stamina every frame and store the result back into stamina itself — no second variable needed. Then add a Float Compare against 0, checked every frame: on equal or less than, transition to the jog state; on greater than, do nothing. This is what prevents infinite sprinting — the moment the tank is empty, the player is forced back to jog whether they're still holding the button or not.
Update the bar
Add a UI Slider Set Value action in the same state, drag the stamina slider in as the game object, use the stamina variable as the value, and check every frame. Because the slider is normalized and stamina runs 0 to 1, the variable maps straight onto the bar with no conversion.
Refill during the jog
Copy the three actions into the jog state and adjust: the Float Operator switches from subtract to add, at half the rate — 0.005 per frame — so recovery costs more time than the sprint bought. Delete the Float Compare entirely; there's no threshold to enforce while refilling. Keep the Set Value action so the bar visibly climbs back toward full. Test the loop: sprint drains the bar, zero snaps you to jog, jogging refills it, and sprinting again drains it — a complete push-your-luck stamina system for any runner.





