Unity + C# Quick Reference

Everything this course uses, on one page. When you forget an API, this is faster than searching the web — and unlike the web, every line here is one you have actually typed this year.

C#What it doesUnity / exam notes
int x = 5;A whole number, 32 bitsCSP: the exam calls these numbers; binary is under the hood
float y = 5.0f;A decimal (the f is required)Unity positions and speeds are floats
bool hasAxe = false;true or false — one bit of informationThe exam: true/false, no third option
string name = "Boss";Text in quotesTags are strings: CompareTag("Coin")
[SerializeField] private float speed;Private in code, editable in the InspectorEvery tuning knob you build uses this pattern
// commentIgnored by the compiler, read by humansYour future self is the human
Debug.Log("Health: " + health);Print to the ConsoleThe exam's DISPLAY(expression)
if (health <= 0) { ... } else { ... }SelectionEvery state machine is built from these
for (int i = 0; i < n; i++) { ... }Counted iterationThe exam: REPEAT n TIMES — and its lists start at 1, yours start at 0
foreach (Card_data c in deck) { ... }Walk a listThe exam: FOR EACH item IN aList
while (alive) { ... }Loop while a condition holdsThe exam: REPEAT UNTIL (condition)
void Heal(int amount) { ... }A method — the exam calls it a procedure; amount is a parameterCreate PT requires a procedure with a parameter
class Boss : MonoBehaviour { ... }A class inheriting MonoBehaviour = a Unity scriptAttach it to a GameObject to run

Unity essentials

Unity APIWhat it doesWhere you used it
void Start()Runs once, first frameSetup: find the player, save startPosition
void Update()Runs every frame — input, movement, checksPlayerController, TurretController, EnemyController
Input.GetAxis("Horizontal")-1 to +1, smoothed — A/D or arrowsMovement (1.4)
Input.GetKeyDown(KeyCode.Space)True only on the frame the key goes downJump (6.1)
Input.GetMouseButtonDown(0)Left click, that frameAttack trigger (1.6)
transform.Translate(v)Move by vector v, ignoring physics entirelyYour first movement (1.4) — replaced in 2.2 once it walked through walls
rb.linearVelocity = vSet how fast the body travels, and let physics do the moving. Units are per second, so it takes no Time.deltaTime.The course's movement method from 2.2 onward. Unity 6 renamed this from velocity — tutorials written before then will not compile.
rb.MovePosition(rb.position + v)Drive the body to a target position along the path, rather than at a speedMoving platforms and scripted set pieces. Stops at walls only on a Dynamic body — the docs recommend Kinematic, which is the one body type it ignores them on.
transform.positionWhere in the world (Vector3)Distance checks
Vector3.Distance(a, b)Straight-line distance between pointsTurret radius (3.1), chase (4.3)
(a - b).normalizedDirection from b to a, length exactly 1Chase (4.3), aiming a projectile (3.2)
Time.deltaTimeSeconds since last frameMultiply motion by it: per-frame, not per-second
Time.timeSeconds since the scene startedCooldowns (3.3, 4.4)
rb.AddForce(Vector2.up * jumpForce, ForceMode2D.Impulse)Push the rigidbody — one impulse beatJump (6.1)
rb.gravityScale0 = float, 2 = fall; swap for game modesTop-down vs cave (5.3), ladders (7.3)
Instantiate(prefab, pos, rot)Clone a prefab into the sceneProjectiles (3.2), card deals (10.2)
Destroy(gameObject)Remove an objectCoin pickup (2.1), projectile death
OnTriggerEnter2D(Collider2D other)Fires when a trigger overlapsCoins, pickups, ladders
OnCollisionEnter2D(Collision2D c)Fires when solid colliders hitSpikes, enemy attack
other.CompareTag("Coin")Identity check by tagEvery pickup pattern
GameObject.FindWithTag("Player")Locate an object by tagTurret and enemy finding you
SceneManager.LoadScene(n) — an int build index, or LoadScene("Platformer") by nameSwap scenes. The index overload is the one this project ships: SceneSwitch.cs holds a serialized int scene, so its value is really a position in Build Settings, not a name.The cave (5.3), the death loop. Reorder Build Settings and every serialized index now points at a different scene — silently, with no error.
SceneManager.GetActiveScene().nameWhich scene is runningDeciding what kind of scene you are in (5.3)
anim.SetBool("IsWalking", b) / SetInteger / SetTriggerDrive the AnimatorWalkDir 0 up / 1 side / 2 down
sprite.flipX = bMirror a spriteFace the walk direction
Random.Range(0, n)Random int 0..n-1 (or float version)Shuffles (10.2c)
DontDestroyOnLoad(gameObject)Survive a scene changeStatManager carrying your coins
Mathf.Min / Max / Abs / FloorToIntNumber helpersHealth cap (2.3), coin halving on death
List<T> + .Add / .RemoveAt / .CountDynamic listCard decks and hands (10.2)

The five patterns that run the whole year

PatternShapeSeen in
Pickuptrigger → CompareTag → change state → Destroycoins, axe, boots, ladders
Cooldownif (Time.time >= last + cooldown) → act, set last = Time.timeturret fire, enemy damage
Scene awarenessread the scene name once in Start → set flags (gravity, movement style)overworld ↔ cave ↔ ladder
State machineflags + nested if/else → behavior per stateenemy patrol/chase/attack, boss phases
Singletonstatic instance + Awake guard + DontDestroyOnLoadStatManager (5.3), GameManager (cards)

If you can rebuild those five from memory, you can rebuild this entire game — which is more or less the point of the semester.

Body Type decides whether the world can stop you. Before you debug any movement or collision problem, read the Rigidbody 2D's Body Type — not your movement code. Only a Dynamic body is stopped by walls and only a Dynamic body produces OnCollision* messages against static colliders. A Kinematic body collides with Dynamic bodies only, so it passes through every wall, floor and cave door in silence. Triggers are the exception: a Kinematic body still fires OnTrigger*, which is why coins keep working and the bug is so hard to see. This project's Player is Dynamic all year, with Gravity Scale 0 in the top-down scenes.
On the AP exam, read the sheet. The exam does not test C# — it ships its own pseudocode reference sheet (1-indexed lists, REPEAT n TIMES, procedures). The full translation lives at Exam Reference Sheet. The muscle you built here transfers; the notation needs ten minutes of practice.

Where this appears in the course