Game Development Reference
In-Depth Information
Appendix A
Important Functions
The purpose of this appendix is to explain the meaning of some important methods used in
Unity, referenced from the Unity Scriping Documentaion.
Awake
The Awake funcion is called when the script instance is being loaded.
Awake is used to iniialize any variable or game state before the game starts. It is called
only once during the lifeime of the script instance. It is also called ater all the objects
are iniialized, so you can safely speak to other objects or query them using, for example,
GameObject.FindWithTag . Each Awake funcion of the GameObject is called in a random
order between objects. Because of this, you should use Awake to set up references between
scripts, and use Start to pass any informaion back and forth. Awake is always called before
any Start funcions. This allows you to order iniializaion of scripts.
For C# and Boo, users use Awake instead of the constructor for iniializaion,
as the serialized state of the component is undeined at construcion ime.
Awake is called once, just like the constructor.
Awake cannot be a corouine.
Example
private var myTarget : GameObject;
function Awake() {
myTarget = GameObject.FindWithTag("Target");
}
Search WWH ::




Custom Search