โœฆ JVDesignStudio ยท No Sign-Up Required

Unity & C# Cheat Sheet

A one-page printable reference for variables, MonoBehaviour lifecycle, components, input and the most-used C# snippets in Unity. Pin it next to your monitor!

๐Ÿ“ฆ Variables & Types

public int health = 100;
public string playerName = "Pip";
public float speed = 4.5f;
private bool isAlive = true;
const int MAX_HP = 100;
[SerializeField] private float jumpForce = 12f;

Use [SerializeField] to expose a private field in the Inspector. public fields show automatically.

โš™๏ธ MonoBehaviour Lifecycle

void Awake() {
    // runs once, before Start
}

void Start() {
    // runs once, before first frame
}

void Update() {
    // runs every frame
    transform.Translate(Vector3.right * speed * Time.deltaTime);
}

void FixedUpdate() {
    // runs on a fixed physics timestep
}

๐Ÿ” Loops & Conditionals

if (health <= 0) {
    Destroy(gameObject);
} else if (health < 20) {
    Debug.Log("Low HP!");
} else {
    Debug.Log("OK");
}

foreach (GameObject enemy in enemies) {
    Destroy(enemy);
}

for (int i = 0; i < 10; i++) { }
while (ammo > 0) { ammo--; }

๐Ÿ“ก Events & Delegates

public static event Action<int> OnHealthChanged;

void TakeDamage(int amount) {
    health -= amount;
    OnHealthChanged?.Invoke(health);
}

// subscribe elsewhere:
void OnEnable() {
    Player.OnHealthChanged += UpdateHpLabel;
}
void OnDisable() {
    Player.OnHealthChanged -= UpdateHpLabel;
}

C# events decouple systems one script broadcasts, others react without direct references.

๐ŸŽฎ Input & Movement

void Update() {
    float h = Input.GetAxis("Horizontal");
    float v = Input.GetAxis("Vertical");
    Vector3 dir = new Vector3(h, 0, v).normalized;
    rb.MovePosition(transform.position + dir * speed * Time.deltaTime);

    if (Input.GetButtonDown("Jump") && isGrounded) {
        rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
    }
}

๐ŸŒณ GameObject & Transform Basics

GetComponent<T>()Get a component on this object
transform.positionWorld-space position
transform.Find("Name")Find a child by name
Instantiate(prefab)Spawn a copy of a prefab
Destroy(obj)Remove a GameObject
gameObject.SetActive(false)Enable/disable an object
tag, CompareTag()Identify object types

๐Ÿงฑ Common Components

TransformPosition, rotation, scale
Rigidbody / Rigidbody2DPhysics-driven movement
Collider / Collider2DCollision & trigger shapes
SpriteRendererDisplays a 2D sprite
AnimatorPlays animation states
AudioSourcePlays sound effects/music
Canvas / RectTransformUI layout root & positioning
NavMeshAgentAI pathfinding movement

โฑ๏ธ Coroutines & Timing

  • StartCoroutine(MyRoutine()) โ€” begin a coroutine
  • yield return new WaitForSeconds(1f); โ€” wait one second
  • yield return null; โ€” wait one frame
  • Time.deltaTime โ€” seconds since last frame
  • Time.timeScale = 0; โ€” pause the game
  • InvokeRepeating("Tick", 1f, 1f) โ€” call a method repeatedly

๐Ÿ› ๏ธ Handy Snippets

// Load a scene
SceneManager.LoadScene("Level2");

// Random number / pick
int roll = Random.Range(1, 7);          // 1-6
string pick = options[Random.Range(0, options.Length)];

// Save / load a value
PlayerPrefs.SetInt("score", 10);
int score = PlayerPrefs.GetInt("score", 0);

// Find objects by tag
GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemy");

// Raycast
if (Physics.Raycast(transform.position, Vector3.down, out RaycastHit hit, 2f)) {
    Debug.Log(hit.collider.name);
}

Want to build a whole game?

Follow one of our free step-by-step workshops in the Workshop hub.

๐Ÿ”ง Browse Workshops โ†’