Show Menu
Cheatography

Unity Editor & C# Reference Cheat Sheet (DRAFT) by

A reference about useful stuff for C# development in Unity.

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Unity Messages

private void Awake() { / Called when the script is being loaded / }
private void OnEnable() { / Called every time the object is enabled / }
private void Start() { / Called on the frame when the script is enabled / }
private void Update() { / Called once per frame / }
private void LateUpdate() { / Called every frame after Update / }
private void OnBecameVisible() { / Called when the renderer is visible by any Camera / }
private void OnBecameInvisible() { / Called when the renderer is no longer visible by any Camera / }
private void OnDrawGizmos() { / Allows you to draw Gizmos in the Scene View / }
private void OnGUI() { / Called multiple times per frame in response to GUI events / }
private void OnApplicationPause() { / Called at the end of a frame when a pause is detected / }
private void OnDisable() { / Called every time the object is disabled / }
private void OnDestroy() { / Only called on previously active GameObjects that have been destroyed / }

Condit­ional Compil­ation

#if UNITY_EDITOR
#if UNITY_STANDALONE
#if UNITY_ANDROID
#if UNITY_WEBGL
#endif

C# Language Features

- Partial Classes allow you to split a class across multiple files
- Implicit Operators to easily convert from one value to another, without explicit casting required
- {{link="https://learn.microsoft.com/de-de/dotnet/csharp/language-reference/keywords/namespace}}Namespaces to provide some structure for your code

Coroutines

yield return null; // Waits until the next Update() call
yield return new WaitForFixedUpdate(); // Waits until the next FixedUpdate() call
yield return new WaitForEndOfFrame(); // Waits until everything this frame has executed
yield return new WaitForSeconds(float seconds); // Waits for game time in seconds
yield return new WaitUntil(() => MY_CONDITION); // Waits until a custom condition is met
yield return new WWW("MY/WEB/REQUEST"); // Waits for a web request
yield return StartCoroutine("MY_COROUTINE"); // Waits until another

Property Attributes

[SerializeField] // serialize and show field in inspector
[HideInInspector]
[RequireComponent(typeof(Collider))]
[Range(0, 100)] // Will show as slider in inspector
[Min(0)]
[Max(100)]
[Header("My Header")] // display header in inspector
[Tooltip("My tooltip")] // tooltip when hovering over it in inspector
[BurstCompile] // use burst compiler
[BurstCompatible] // ensure class stays burst compatible