Hey guys,
I have a health bar in the form of a guitexture in a rectangle, and I was wondering how to make it so that it slowly depreciates over a time limit, and when you collect a certain item it goes back up a little bit?
I can’t find any relevant examples, and I suck at scripting, any help would be greatly appreciated!
I have included my script which displays my health bar. But how do I make it say, lose 1 hitpoint every second?
And what do you add to this script to say that when you hit another specified gameobject in the game, you get 20 hitpoints added?
theres a good tutorial on GUI’s and health on the main unity support page… lerpz 3rd person platformer. they go over how to add health when you hit a prefab as a trigger… hope that helps
Alright, but what I want to do is have the players health bar constantly decreasing.
I have got it so that when you click the mouse the health goes down, but how do I make it go down by itself?
Code:
well just put UpdateGUI code in a coroutine / update , whatever you prefer and do same things , just multiply your decreasing value with something like Time.deltaTime so it will decrease slowly over time.
I have no Idea how to script that is why I’m asking on the forums for how to do it. I don’t even know what you mean by making a coroutine?
http://unity3d.com/support/documentation/ScriptReference/index.Coroutines_26_Yield.html
do yourself a favor, try to figure out by yourself, then if really you can’t do it , ask for code ^^…that’s the way to progress