Add one number to another in the update function, once.

I need to add one number to another in the update function but since its the update function it keeps adding, over and over. I've tried several things to get it to add only once like a true/false statment, only add if blah = true then turn it false after the calc statment but it still does one more add than I need.

How do you suggest I do this? I get the feeling it's super simple but my head hurts. :D

Thanks.

I am siding with Eric...you should find a better way. However, to relieve your wonder, it would look like this:

bool ranOnce = false
int foo = 0;

void Update()
{
    if (!ranOnce)
    {
        ranOnce = true;
        foo+=;
    }
}

better would be something like:

void AddToFoo( int amount )
{
    foo += amount;
}

...

from somewhere else, like an event:

myScriptComponent.AddToFoo( myAmount );

Since you only want to do it once, then it doesn't belong in Update in the first place.

The update function is called a few hundred times a second, so that is not going to do you much good, try something like the awake function, so you could keep your old code, but just change the Update() to Awake() That should fix your problem, if it doesn't, then try a different function. You can find a list of functions (big list :P) on this like: http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.CancelInvoke.html They will be down the left hand side under: Functions

Hope this helps

-Grady