Game Development Reference
In-Depth Information
Example
// Apply an upward force to the rigidbody every frame
function FixedUpdate () {
rigidBody.AddForce(Vector3.up);
}
LateUpdate
LateUpdate
is called for every frame, if
MonoBehaviour
is enabled.
LateUpdate
is called after all
Update
funcions have been called. This is useful to
order script execuion. For example, a follow camera should always be implemented in
LateUpdate
because it tracks objects that might have moved inside
Update
.
Example
// Moves the object forward 1 meter per second
function LateUpdate () {
transform.Translate(0, 0, Time.deltaTime*1);
}
OnGUI
OnGUI
is called for rendering and handling GUI events, such as
GUI.Button
,
GUI.Label
,
GUI.Box
, and so on.
This means that your
OnGUI
implementaion might be called several imes per frame (one
call per event). If the
enabled
property of
MonoBehaviour
is set to
false
,
OnGUI
will not
be called.
Example
// Draw the Button (width = 150, height = 50) at the position x = 10,
y = 10.
function OnGUI () {
if (GUI.Button(Rect(10, 10, 150, 50), "My Button")) {
Debug.Log("Hello World");
}
}