How do I implement a method to do something like this in my game:
My Hero needs to eat food within 5 sec. or else my animation will change to hungry…
Is there anyway I can detect if it reaches to 5 sec. before I’ll change the animation to hungry?
How do I implement a method to do something like this in my game:
My Hero needs to eat food within 5 sec. or else my animation will change to hungry…
Is there anyway I can detect if it reaches to 5 sec. before I’ll change the animation to hungry?
Need to loop back again to count for 5 sec. to eat food again.
Add a “float hungryTime” property to your script. This represents the time (i.e. Time.time value) at which your character will be hungry again.
When he eats something, set that property to Time.time + 5 (or whatever you feel is appropriate).
Then in your Update method, use a simple if statement… if (Time.time > hungryTime), then change your animation or do whatever else you do in response to hunger.
I will try this one. Then return back for result… thank you.
it works perfectly!