|
If my question was a bit vague i'll expand here; Basically what i want to do is have a little icon of a stomach (To represent hunger) and every frame have a variable that contains the hunger decrease by 0.1. Once the hunger level reaches certain intervals, i want the color to change on the guiTexure, for example; at 500.0f color = yellow at 250.0f color = red I'm fairly new to scripting in unity, so i could be way off with this code, so can somebody please help me It will decrease the CurrentHunger variable, however the colors do not change at the intervals. Here's my code;
(comments are locked)
|
|
A line like this: is actually testing whether or not x.xxxxxxxxx is exactly equal to 500.0000000 which is a bad way to do things. Even if your logic makes it clear that the if statement should trigger at some point, floating point numbers are not 100% accurate, and so still may not end up exactly the value you expect. instead, use less-than and greater-than checks: Yup that worked, i also needed to call the OnGui function in update and that got it working, thanks.
Aug 20 '12 at 09:18 PM
Ufando
Oh, you shouldn't need to do that. You actually just need to rename the function from "OnGui" to "OnGUI".
Aug 21 '12 at 04:36 AM
Khada
(comments are locked)
|

Did that do the trick? Don't forget to mark the question as answered if it did.