Game Development Reference
In-Depth Information
}
if(bButtonDown && !Input.GetMouseButton(0))
{
bButtonDown = false; SendMessage("OnMouseUp", SendMessageOptions.
DontRequireReceiver);
}
}
else
{
//Was previously entered and now leaving
if(bIntersected) SendMessage("OnMouseExit",
SendMessageOptions.DontRequireReceiver);
bIntersected = false;
bButtonDown = false;
}
//Wait until next frame
yield return null;
}
}
//---------------------
}
//---------------------
Coroutines
Coroutines are a special kind of function. They behave like threads insofar
as they appear to run in parallel or asynchronously to the main game
loop, that is, once you execute them, they seem to run in the background.
Execution doesn't pause or wait until the function is completed as it
does with traditional functions. This makes Coroutines great for creating
asynchronous-looking behaviors. Technically, all Coroutines must
return a type of IEnumerator , contain at least one yield statement in
their body, and must be launched with the StartCoroutine function.
The yield statement is a special statement that suspends execution of
the Coroutine until its condition is met. The statement yield return new
WaitForSeconds(x) will pause execution for x seconds, resuming after
the interval at the next line. In contrast, the statement yield returned null
will suspend execution for the current frame, resuming execution at the
next line on the next frame. More information on Coroutines and their use
can be found in the Unity documentation at http://docs.unity3d.
com/Manual/Coroutines.html .
 
Search WWH ::




Custom Search