|
hello everyone, So I have this value: public int gold = 400; That is located on another script. I want, first of all, to get access to this value, which is not complicated. My problem is mostly that I need to do a function that will repair the hp of an object (a repair function) based on this value. It will increment hp by 1 by frame (or more) up to full hp. But each "digit" restored must cost something, so I need to decrease the value of gold as long as this function is active. I have no clue how to do that. I've been working on this for the last hours... Any suggestions? :S NOTE : I code in c#.
(comments are locked)
|
|
For anything over time, think Update or coroutines. Each occurence of the event "I give 1 hp, but gimme the money mate !" you need to 1) check if there is enough gold 2) increase hp 3) deacrease the gold. It's probably going to look like that : Interesting, I'll try this. Also, is there a way to stop the coroutine, or this code, in any way other than to wait for the while to reach its end? (ex: user press a key, or click on a particular button)
Apr 25 '12 at 07:07 PM
Herve_Simard
you can get out with if(Input.GetKeyDown(Choose a button))break;
Apr 25 '12 at 07:17 PM
fafase
But the Coroutine will work nonetheless... that's what I heard / read...
Apr 25 '12 at 07:48 PM
Herve_Simard
There is three ways to stop a coroutine, that I can think of at least :
Apr 25 '12 at 07:59 PM
Berenger
(comments are locked)
|
