Updates in Unity 5.5
from: https://docs.unity3d.com/ScriptReference/MonoBehaviour.Update.html
Update is called every frame, if the MonoBehaviour is enabled. Update is most commonly used function to implement any kind of game behaviour.
using UnityEngine; using System.Collections; public class ExampleClass : MonoBehaviour { void Update () { transform.Translate (0, 0, Time.deltaTime * 1); } }
In order to get the elapsed time since the last call to Update , use Time.deltaTime . This function is only called if the Behaviour is enabled. Override this function in order to provide your component’s functionality.
from: Unity 5.x By Example by Alan Thorn
In addition to the Update function called on each frame, Unity also supports two other related functions, namely, FixedUpdate and LateUpdate . FixedUpdate is used when coding with Physics, and is called a fixed number of times per frame. LateUpdate is called once per frame for each active object, but the LateUpdate call will always happen after every object has received an Update event. Thus it happens after the Update cycle, making it a late update.
from: https://docs.unity3d.com/ScriptReference/MonoBehaviour.FixedUpdate.html
This function is called every fixed framerate frame, if Monobehaviour 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 every fixed frame inside FixedUpdate instead of every frame inside Update .
using UnityEngine; using System.Collections; public class ExampleClass : MonoBehaviour { public Rigidbody rb; void Start () { rb= GetComponent<Rigidbody> (); } void FixedUpdate () { rb.AddForce (10.0f * Vector3.up); } }