Game Development Reference
In-Depth Information
Start
Start
is called just before any of the
Update
methods are called.
Start
is only called once in the lifeime of the behavior. The diference between
Awake
and
Start
is that
Start
is only called if the script instance is enabled. This allows you to delay
any iniializaion code, unil it is really needed.
The
Start
funcion is called ater all
Awake
funcions on all script instances have been called.
Example
private var myLife : int;
function Start() {
myLife = 5;
}
Update
Update
is called for every frame, if
MonoBehaviour
is enabled.
Update
is the most commonly used funcion to implement any kind of game behavior.
Example
// Moves the object forward 1 meter per second
function Update () {
transform.Translate(0, 0, Time.deltaTime*1);
}
FixedUpdate
FixedUpdate
is called for every fixed framerate frame, if
MonoBehavior
is enabled.
FixedUpdate
should be used instead of
Update
when dealing with Rigidbody. For example,
when adding a force to a rigidbody, you have to apply the force for every fixed frame inside
FixedUpdate
instead of every frame inside
Update
, because the physics simulaion is
carried out in discrete imesteps. The
FixedUpdate
funcion is called immediately before
each step.