MonoBehaviour Event Execution Order
Ordered by first to last method to execute.
private void Awake() { }
private void OnEnable() { }
private void Start() { }
private void Update() { }
private void LateUpdate() { }
private void OnBecameVisible() { }
private void OnBecameInvisible() { }
private void OnDrawGizmos() { }
private void OnGUI() { }
private void OnApplicationPause() { }
private void OnDisable() { }
private void OnDestroy() { }
Physics updates on a Fixed Timestep are defined under Edit => Project Settings => Time => Fixed Timestep and may execute more or less than once per actual frame.
private void FixedUpdate() { }
See the Physics Events section for a quick reference on associated Physics methods.
GameObject Manipulation
Instantiate(GameObject prefab);
Instantiate(GameObject prefab, Transform parent);
Instantiate(GameObject prefab, Vector3 position, Quaternion rotation);
Instantiate(bullet);
Instantiate(bullet, bulletSpawn.transform);
Instantiate(bullet, Vector3.zero, Quaternion.identity);
Instantiate(bullet, new Vector3(0, 0, 10), bullet.transform.rotation);
Destroy(gameObject);
GameObject myObj = GameObject.Find("NAME IN HIERARCHY");
GameObject myObj = GameObject.FindWithTag("TAG");
Example myComponent = GetComponent<Example>();
AudioSource audioSource = GetComponent<AudioSource>();
Rigidbody rgbd = GetComponent<Rigidbody>();
Vector Quick Reference
X = Left/Right Y = Up/Down Z = Forward/Back
Vector3.right Vector2.right
Vector3.left Vector2.left
Vector3.up Vector2.up
Vector3.down Vector2.down
Vector3.forward
Vector3.back
Vector3.zero Vector2.zero
Vector3.one Vector2.one
float length = myVector.magnitude
myVector.normalized
Time Variables
float timeSinceStartOfGame = Time.time;
float currentTimeScale = Time.timeScale;
Time.timeScale = 0;
float timePassedSinceLastFrame = Time.deltaTime;
float physicsInterval = Time.fixedDeltaTime;
Physics Events
private void OnCollisionEnter(Collision hit) { Debug.Log(gameObject.name + " just hit " + hit.gameObject.name); }
private void OnCollisionStay(Collision hit) { Debug.Log(gameObject.name + " is hitting " + hit.gameObject.name); }
private void OnCollisionExit(Collision hit) { Debug.Log(gameObject.name + " stopped hitting " + hit.gameObject.name); }
private void OnTriggerEnter(Collider hit) { Debug.Log(gameObject.name + " just hit " + hit.name); }
private void OnTriggerStay(Collider hit) { Debug.Log(gameObject.name + " is hitting " + hit.name); }
private void OnTriggerExit(Collider hit) { Debug.Log(gameObject.name + " stopped hitting " + hit.name); }
private void OnCollisionEnter2D(Collision2D hit) { }
private void OnCollisionStay2D(Collision2D hit) { }
private void OnCollisionExit2D(Collision2D hit) { }
private void OnTriggerEnter2D(Collider2D hit) { }
private void OnTriggerStay2D(Collider2D hit) { }
private void OnTriggerExit2D(Collider2D hit) { }
Coroutines
private IEnumerator CountSeconds(int count = 10)
{
for (int i = 0; i <= count; i++) {
Debug.Log(i + " second(s) have passed");
yield return new WaitForSeconds(1.0f);
}
}
StartCoroutine(CountSeconds());
StartCoroutine(CountSeconds(10));
StartCoroutine("CountSeconds");
StartCoroutine("CountSeconds", 10);
StopCoroutine("CountSeconds");
StopAllCoroutines();
private IEnumerator countSecondsCoroutine;
countSecondsCoroutine = CountSeconds();
StartCoroutine(countSecondsCoroutine);
StopCoroutine(countSecondsCoroutine);
yield return null;
yield return new WaitForFixedUpdate();
yield return new WaitForEndOfFrame();
yield return new WaitForSeconds(float seconds);
yield return new WaitUntil(() => MY_CONDITION);
yield return new WWW("MY/WEB/REQUEST");
yield return StartCoroutine("MY_COROUTINE");
Input Quick Reference
if (Input.GetKeyDown(KeyCode.Space)) { Debug.Log("Space key was Pressed"); }
if (Input.GetKeyUp(KeyCode.W)) { Debug.Log("W key was Released"); }
if (Input.GetKey(KeyCode.UpArrow)) { Debug.Log("Up Arrow key is being held down"); }
if (Input.GetButtonDown("ButtonName")) { Debug.Log("Button was pressed"); }
if (Input.GetButtonUp("ButtonName")) { Debug.Log("Button was released"); }
if (Input.GetButton("ButtonName")) { Debug.Log("Button is being held down"); }
Hotkeys