Reassigning Update() function via script possible ?

To prevent unity from having to reevaluate an if statement each frame, i would like to know if its possible to reassign the update function via script during runtime. So that only after a specific event the Update-function gets activated
like:

function myOwnUpdate()
{
   DosomethingRealImportant();
}

function onImportandEvent()
{
    // after this, myOwnUpdate get's called each frame
    Update = myOwnUpdate;
}

Is this possible ? - I’m coming from Actionscript, where this IS indeed possible…

thx in advance !

Have the two Update functions in two different scripts, then enable/disable the scripts as desired.

More elegantly, use coroutines instead of Update.

–Eric

I think you should not worry about the performance impact of one if-statement. Unless your update is called thousands upon thousands of times per frame and has virtually no other code besides that if-statement, the performance impact will be unmeasurable.

The trick is not not to care about performance until you run into to actual performance problems. If you don’t, you’re bound to sacrifice program readability and possibly stability for slightly better performance of code that is not even a bottleneck.

thx for the tips guys…

this is on iphone so i thought performance optimizing is crucial…
But anyway, i already decided that’s not worth the effort
but thanks again !

ah tom - just saw you work for stickystudios

your site, and the great graphics&gameplay of “Temple Troubles” was some major motivation to dig deeper into AS3 coding. Over the last few years I revamped pre-AS3 coded flashgames (3D GFX codewise), and i really started to love AS3 - but hey -now its unity time :wink:
Anyway - back then i thought it would be cool to work at your company (since you got job offers for both 3ds max + Flash game programmer) - but here’s me, still sitting in Vienna, fighting to make a living with all this indie/casual gameing stuff myself…

That’s awesome :smile:

I can’t take any credit for Temple Trouble, sadly, as I wasn’t involved in that project ;).

one of the things u can do is code several update methods UpdateCaseWorking, UpdateCaseLeaving, UpdateCaseInProcess,… and then have ur update method call the proper one through a function delegate called currentUpdateMethod.

I second the above. Learn more about .NET 1.1 Delegates here:

http://msdn.microsoft.com/en-us/library/900fyy8e(VS.80).aspx

(We need to use .net1.1 for iPhone)