Spending energy code

Hello, i want insert a bar that, when the player move around decrease (not when is still coz sometime gamers can leave the game on standby doing something) it can be stamina, energy, hunger, thirst but can’t figure out how do to that. My main problem is how to code it when the player move, to make it decrese as time passes. Someone have an idea how i can make this?

Think about your problem. Then break it into smaller parts. Then solve each part. If each part is complicated then break that part into more parts. Solve those.

This is really a very generic system that you need to create so just sit down and think about it and try to ask a question if you get really stuck on one of those parts that you broke your task into.