For some reason I can’t get this to work right even though the logic seems sound.
I have a GUI box that scales down proportionally based on how much of one int there is versus another. It looks like this:
var current : int;
var maximum : int;
function Start (){
maximum = 100;
current = maximum;
}
function OnGUI (){
GUI.Box(new Rect(10,10 + Screen.height / 24,(Screen.width * current / maximum / 2), Screen.height / 24));
if(GUI.Button(new Rect(Screen.width / 8, Screen.height / 4, Screen.width / 16, Screen.width / 16), "Subtract"))
{
current -= 10;
}
}
function Update () {
if(current < maximum)
{
current += Time.deltaTime;
}
}
My problem is that it either does not work at all and adds nothing after the current amount is subtracted, or it adds too fast and goes back completely in less than a second or two. I only want the amount to change once per second. (Note that this is code I wrote just this moment as a quick demonstration of what is happening, the full code is too long to post, but the mechanics aren’t changed).