(C# newbie) - How to create hunger and thirst for a character

Sorry, it was hard for me to word the question in the thread title.

I’m assuming this would be done similar to how health reaching zero would kill the player.

How would I make it so that

a) the player hunger bar will decrease over time, with an exponential effect to it, meaning the hungrier you are, the hungrier you get.
b) after x amount of time not eating food (which might be as simple as clicking an item on the gui in the player inventory), player will die
c) if possible, could you explain how I could make a debuff after X amount of time not eating? im sure this would have to tap into other character stats, or it could use a more basic stamina drain increase (so the player cannot sprint for as long, etc)

what if i wanted to do one for thirst? i was thinking the same thing with a GUI, with a canteen in the inventory. however for this i would need

a) player interacts with object in the game world (barrels of water, a river, etc), canteen fills up.
b) player drinks, thirst bar fills 1/4, canteen empties 1/4 of its “charges”
c) thirst bar decays at X rate with an exponential effect
d) thirst bar reaches zero kills player

Also, if you could recommend any c# books or tutorials that you think are very effective, I would greatly appreciate it! :slight_smile:

Thanks, I hope someone out there likes answering these types of questions. I would pay someone to do small time coding for me if I had to (if I could not learn it myself)

Fundamentally the answer to your question is to track player state in a couple variables, the timestamps of last hunger update, and then every Update() you increment your hunger variable by the amount specified by your algorithm there.

Your question suggests you don’t really have any experience programming. You can definitely learn to program by writing a game, but I think I’d recommend practicing some programming with some pure programming exercises so the Unity engine doesn’t confuse you. Once you understand how to write software you can apply those concepts to the Unity engine.

Go here to learn C# and get an idea of how you might write this system.