Unity Intro
Unity is a game engine and editor. You build scenes out of objects in the editor, attach behaviour to them with C# scripts, and export the result to Windows, macOS, Linux, Android, iOS, the web and consoles. It is the most widely used engine for mobile and indie games, and it is used for VR, simulations and film previsualization as well.
This course targets Unity 6 (version numbers 6000.x), using the Universal Render Pipeline (URP) and the Input System package. If you learned Unity before 2023, some names have changed. They are flagged in the lessons with a "Migrating" note.
What you need first
- C# basics: classes, properties, interfaces, generics,
List<T>, events and lambdas. The C# course covers all of them. - The game loop, delta time and fixed timesteps from Game Development Roadmap & Fundamentals. Unity's
UpdateandFixedUpdateare those ideas with engine names. - Vectors and dot products, from Math for Games.
How this course works
Unity can't run inside a web page lesson, so every topic comes in two forms:
- Real Unity code in plain
csharpblocks. You paste it into a script in your own project. It uses current Unity 6 APIs. - A runnable model of the same idea in plain C#, which runs on this site (.NET, through Compiler Explorer). The model removes the engine and keeps the mechanism: the lifecycle order, how "fake null" works, how a pool recycles objects, how an ECS iterates arrays.
Here is the smallest version of the trick. Unity calls methods on your components; you never write Main. A model of that is a loop that calls them for you:
using System;
using System.Collections.Generic;
var scene = new List<Behaviour> { new Spinner(), new Spinner { Speed = 180 } };
float deltaTime = 0.5f; // pretend each frame takes half a second
foreach (var b in scene) b.Start();
for (int frame = 1; frame <= 3; frame++)
{
foreach (var b in scene) b.Update(deltaTime);
Console.WriteLine(quot;frame {frame}: " + string.Join(", ", scene));
}
abstract class Behaviour
{
public virtual void Start() { }
public virtual void Update(float dt) { }
}
class Spinner : Behaviour
{
public float Speed = 90; // degrees per second, like a public Inspector field
float angle;
public override void Start() => angle = 0;
public override void Update(float dt) => angle = (angle + Speed * dt) % 360;
public override string ToString() => quot;{angle:F0} deg";
}frame 1: 45 deg, 90 deg
frame 2: 90 deg, 180 deg
frame 3: 135 deg, 270 deg
And here is the same component in Unity:
using UnityEngine;
public class Spinner : MonoBehaviour
{
[SerializeField] float speed = 90f; // degrees per second, editable in the Inspector
void Update()
{
transform.Rotate(0f, speed * Time.deltaTime, 0f);
}
}The engine finds every enabled MonoBehaviour in the loaded scenes and calls Update once per frame. Time.deltaTime is the frame time in seconds.
Your first project
- Install Unity Hub, then a Unity 6 LTS editor through it (see Unity Hub, Modules & IDEs).
- In the Hub, choose New project and pick the Universal 3D template (named "3D (URP)" in some versions). It sets up URP, the Input System and a sample scene.
- Name the project, choose a folder outside cloud-synced directories (OneDrive and Dropbox fight with Unity's file writes) and create it.
- In the Project window, right-click
Assets, choose Create, then MonoBehaviour Script (newer 6.x releases group it under Scripting), and call itSpinner. The class name must match the file name. - Paste the code above, save, and wait for Unity to recompile (the spinner in the bottom-right corner).
- Add a cube (GameObject > 3D Object > Cube), drag the script onto it, and press Play.
What's in the course
| Section | You learn |
|---|---|
| Editor, GameObjects, Scripting | scenes, components, prefabs, the lifecycle, serialization, coroutines, Awaitable, events |
| Input and Physics | the Input System, rebinding, Rigidbody, colliders, raycasts, CharacterController |
| Data, UI, Audio, 3D | ScriptableObjects, saving, Addressables, UI Toolkit, AudioMixer, URP, Cinemachine, Animator, NavMesh, VFX |
| Architecture and Performance | event channels, services, state machines, tests, the Profiler, GC, pooling |
| DOTS, Multiplayer, Shipping | ECS, Jobs, Burst, Netcode for GameObjects, build profiles, IL2CPP |
| Toolkit and Field notes | packages, IDEs, Asset Store tools, version control, hard-won advice |
You finish with Crystal Run, a small 3D collect-and-escape game.
Test yourself
Which Unity version line does this course target?
- Unity 2019 LTS
- Unity 6 (6000.x)
- Unity 5
- Unity 2021 with the old Input Manager
Who calls a MonoBehaviour's Update method?
- Your
Mainmethod - The engine, once per frame for every enabled component
- Only the Inspector
- The physics system, 50 times per second
Why does each Unity topic in this course also have a plain C# model?
- Unity code is slower
- The site can run plain C#, so the model shows the mechanism in a form you can execute
- Unity does not use C#
- Models replace Unity in production