all we know update() functions are expensive… i´m implementing time every 1 hour… … Unity detects every one hour and it does an activity according to that…
static var changeWorld = false;
function Update(){
CheckTime();
}
function CheckTime(){
if (changeWorld){
//here some events..
}
}
does this code waste too much memory or resources having in mind that the most of the time the changeWorld var is false ?
I’d say no. Simple boolean check every frame is nothing (in terms of resources).
If you do something every one hour exactly you can also use a coroutine for this. WaitForSeconds().
This might save a few clock cycles, I am not sure that it will, but the real benefit is better looking code.
While Ivkoni is right on a desktop platform, on iPhone the Update call itself it noticeably expensive. It uses Reflection and when you have 20 or so Update calls you will start to see noticeable performance drops.
Using a WaitForSeconds Coroutine or having a single Manager that is registered to and that Manager calls your Update through delegates avoids the reflection slowdown(if done right can result in incredibly suprising framerate gains).
Something Like
void Start()
{
StartCoroutine(CheckTime());
}
IEnumerator CheckTime()
{
while(true)
{
yield return new WaitForSeconds(60 * 60);//number of seconds per minute times number of minutes
//Do worldChange code here.
}
}
But if it’s on a desktop, overusing Update a little bit really shouldn’t be any sort of problem worth worrying over too much.
is for desktop users… i guess update is good, but… i´m thinking in take in mind your script Ntero cuz there are really many update() functions, is good to let a Coroutine too… Thanks both!