How to Make a Game in Unity: Beginner's Guide

Learn how to make a game in Unity 6 step by step: install Unity Hub, learn the editor, build a small 2D coin game with score, timer and restart, then share it.

首页 › 攻略 › How to Make a Game in Unity: Beginner's Guide

Illustration: Make Your First Game in Unity

To make a game in Unity, you install Unity Hub, add a Unity 6 editor and start a project from a template. Then you build the game out of GameObjects, components and short C# scripts. This guide walks you through every step by building Coin Rush, a tiny 2D game: move a square, grab coins before the timer runs out, dodge spikes and restart with one key. At the end you turn it into a real program your friends can play.

Time neededOne weekend (4 to 6 hours)
CostFree with Unity Personal
You needA Windows, Mac or Linux PC
Skill levelTotal beginner

What you need before you start

Unity is a game engine. A game engine is a program that does the hard parts of a game for you: drawing graphics, running physics, playing sound and reading the controller. You bring the art and the rules. Hollow Knight, Cuphead and Among Us were all made with Unity.

  • A computer. Windows 10 or 11, macOS 13 Ventura or newer, or Ubuntu 22.04 or 24.04. Unity recommends at least 8 GB of RAM.
  • Free disk space. Plan for roughly 15 GB for the editor, a code editor and your projects.
  • A free Unity account. You must be old enough to agree to data use where you live. That is 13 in the US and up to 16 in parts of Europe. If you are younger, a parent or guardian needs to create the account and use it with you.
  • No money. Unity Personal is free while your revenue and funding stay at or below 200,000 US dollars a year (as of November 2026).
Good to know

Unity games are programmed in C# (say "C sharp"). You don't need to know it yet. This guide gives you every line of code and explains it.

How to install Unity 6 with Unity Hub

Unity Hub is a small launcher app. It installs Unity versions, signs you in and keeps all your projects in one list.

  1. Download Unity Hub from unity.com and install it like any other program.
  2. Sign in or create your Unity account. Signing in activates the free Personal license automatically. If it doesn't, open Settings > Licenses > Add license and choose Get a free personal license.
  3. Install an editor. Click Installs on the left, then Install Editor. On the Official releases tab, pick the newest Unity 6 version marked LTS (long-term support). In November 2026 that is Unity 6.3 LTS. Newer supported versions, such as Unity 6.6, also work with this guide.
  4. Pick modules. Modules are add-ons. On Windows, keep the code editor the Hub offers, Visual Studio. On a Mac or Linux, install Visual Studio Code with Microsoft's Unity extension, or JetBrains Rider. Tick Web Build Support if you want a browser version later. Skip Android and iOS for now.
  5. Click Install and wait. The download is several gigabytes.

Now create the project. Click Projects > New project, choose the Universal 2D template (download it first if the Hub asks), name it CoinRush and click Create project. A template is a starter project with the right settings already on. Universal 2D sets up 2D graphics and the Input System, the part of Unity that reads keyboards, gamepads and touch screens. The official Unity Hub install guide has screenshots of each step.

Tip

Stick to one Unity version per project. Opening a project in a newer version upgrades it, and going back is hard. Make a backup copy of the project folder before any upgrade.

The Unity editor explained

When the project opens, you only need six areas of the editor at first.

  • Hierarchy: a list of everything in the current scene. A scene is one level or screen of your game.
  • Scene view: your workshop. Click an object to select it, then drag it around.
  • Game view: what the player sees through the camera.
  • Inspector: the settings of whatever you selected. You change colors, sizes and script values here.
  • Project window: every file in your game, such as images, sounds, scripts and scenes.
  • Console: messages from Unity, in a tab next to the Project window. Red lines are errors, and they always need fixing first.
The main windows of the Unity editor A sketch of the default Unity 6 layout. The toolbar with the Play button is at the top. The Hierarchy is on the left, the Scene and Game view in the middle and the Inspector on the right. The Project window and the Console share the bottom panel as two tabs. Toolbar: Play, Pause and Step buttons Hierarchy list of every object in the open scene Main Camera Player Coin Scene / Game view Scene tab: place and move things Game tab: what the player sees Inspector settings and components of the selected object Transform Rigidbody 2D Project window your files: sprites, scripts, sounds, scenes and prefabs Console messages and errors, a tab beside Project
The default Unity 6 layout. Select something in the Hierarchy, then change it in the Inspector.

The Play button at the top runs your game inside the editor. Press it again to stop.

Watch out

Anything you change while the game is playing is thrown away when you stop. Stop first, then edit. To make Play mode easy to spot, pick a strong Playmode tint in Edit > Preferences > Colors (on a Mac, Unity > Settings).

GameObjects and components: how Unity games are built

Everything in a scene is a GameObject: the player, each coin, the camera, even the score text. On its own, a GameObject is just an empty container with a name.

You give it abilities by adding components. A Sprite Renderer draws a picture. A Rigidbody 2D lets physics move it. A collider gives it a shape that can touch other things. Scripts you write in C# are components too.

A GameObject is a container of components The Player GameObject on the left connects to five components on the right: Transform for position, rotation and scale; Sprite Renderer to draw the square; Rigidbody 2D for physics; Box Collider 2D for its touch shape; and PlayerController, your own C# script that reads input. Player a GameObject (the container) Transform position, rotation and scale Sprite Renderer draws the blue square Rigidbody 2D physics: speed, pushes and bumps Box Collider 2D the invisible shape that touches things PlayerController your C# script: reads input and moves
One GameObject, five components. Each component adds one ability, and your script is just another component.

Every GameObject has a Transform. It stores where the object is, how it's turned and how big it is. One more word before you start: a prefab is a saved GameObject you can copy as often as you like. Change the prefab, and every copy changes with it. You will use prefabs for the coins and spikes.

Step 1: Make a player that moves

Coin Rush is a top-down game. The camera looks down at a flat arena, so nothing should fall.

  1. Create the player. In the Hierarchy, click + and choose 2D Object > Sprites > Square. Name it Player. In the Inspector, click the Color field of the Sprite Renderer and pick blue.
  2. Add physics. Click Add Component, search for Rigidbody 2D and add it. Set Gravity Scale to 0, or the player drops off the screen. Open Constraints and tick Freeze Rotation Z so it doesn't spin after a bump.
  3. Add a shape. Add a Box Collider 2D. A collider is the invisible shape Unity uses to detect touches.
  4. Create the script. In the Project window, right-click the Assets folder and choose Create > Scripting > MonoBehaviour Script. Name it PlayerController right away, so the file name matches the class name inside.
  5. Write the code. Double-click the script to open your code editor. Replace everything with this code and save.
using UnityEngine;
using UnityEngine.InputSystem;

// Moves the player with the keyboard or a gamepad.
public class PlayerController : MonoBehaviour
{
    [SerializeField] float speed = 6f; // units per second

    InputAction moveAction;
    Rigidbody2D body;

    void Start()
    {
        // "Move" is ready-made in new Unity 6 projects:
        // WASD, the arrow keys and the gamepad stick.
        moveAction = InputSystem.actions.FindAction("Move");
        body = GetComponent<Rigidbody2D>();
    }

    void FixedUpdate()
    {
        // A direction from -1 to 1 on each axis.
        Vector2 input = moveAction.ReadValue<Vector2>();
        body.linearVelocity = input * speed;
    }
}

Back in Unity, wait while it compiles. Drag PlayerController from the Project window onto the Player in the Hierarchy. Press Play and move with WASD, the arrow keys or a gamepad. Stop, then save with Ctrl+S (Cmd+S on a Mac) after every step.

Here is what the code does. Start runs once when the game begins. FixedUpdate runs at a steady rate, in step with physics. The "Move" action lives in an asset called InputSystem_Actions that new Unity 6 projects include. linearVelocity sets the speed and direction of the body. Older tutorials call it velocity, but Unity 6 renamed it.

Because speed has [SerializeField] in front, it shows up in the Inspector, so you can tune it without touching the code.

Step 2: Add coins, spikes and walls

  1. Make a coin. Add 2D Object > Sprites > Circle, name it Coin and color it yellow. Set its Scale to 0.5 on X and Y. Add a Circle Collider 2D and tick Is Trigger.
  2. Create a Coin tag. Open the Tag menu and choose Add Tag. Click +, type Coin and save. Select the coin again and set its tag to Coin. Tags are case-sensitive, so "coin" will not work.
  3. Turn it into a prefab. Drag the coin from the Hierarchy into the Project window. Its icon turns blue. Press Ctrl+D (Cmd+D on a Mac) in the scene until you have eight coins, and spread them out.
  4. Make spikes. Add 2D Object > Sprites > Triangle and color it red. Add a Polygon Collider 2D and tick Is Trigger. Give it a new Spike tag, make it a prefab and place three or four.
  5. Build walls. Add four Squares, each with a Box Collider 2D, and leave Is Trigger off. Top wall: position (0, 4.75), scale (18, 0.5). Bottom wall: position (0, -4.75), same scale. Left wall: position (-8.65, 0), scale (0.5, 10). Right wall: position (8.65, 0), same scale.

Why tick Is Trigger? A trigger notices when something overlaps it but doesn't block it. Coins and spikes should be noticed. Walls should block, so they stay normal colliders. Trigger messages only arrive when at least one of the two objects has a Rigidbody 2D.

Step 3: Score, timer, win and lose

  1. Add text. In the Hierarchy, click + > UI > Text - TextMeshPro. Newer versions may call it UI (Canvas). If Unity offers to import TMP Essentials, accept. Unity also adds a Canvas, the layer that holds on-screen text and buttons.
  2. Make three labels. Rename the text ScoreText. In its Rect Transform, set Width to 400 so the text fits on one line, then drag it to the top-left corner. Duplicate it twice: TimerText goes top-right, and MessageText goes in the center. Give MessageText a Width of 1200, a font size of 72 and centered alignment.
  3. Keep the text sized right. Select the Canvas. In Canvas Scaler, set UI Scale Mode to Scale With Screen Size and the reference resolution to 1920 by 1080.
  4. Create the manager. Click + > Create Empty and name it GameManager. Create a MonoBehaviour Script called GameManager, paste in this code and attach it to the new object.
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.SceneManagement;
using TMPro;

// Counts coins, runs the timer and ends the game.
public class GameManager : MonoBehaviour
{
    [SerializeField] TMP_Text scoreText;
    [SerializeField] TMP_Text timerText;
    [SerializeField] TMP_Text messageText;
    [SerializeField] float timeLimit = 30f;

    int coins;
    int coinsToWin;
    float timeLeft;
    bool gameOver;

    void Start()
    {
        Time.timeScale = 1f; // unfreeze after a restart
        coinsToWin =
            GameObject.FindGameObjectsWithTag("Coin").Length;
        timeLeft = timeLimit;
        messageText.text = "";
        UpdateTexts();
    }

    void Update()
    {
        if (gameOver)
        {
            // R reloads this scene for a fresh start.
            var keys = Keyboard.current;
            if (keys != null && keys.rKey.wasPressedThisFrame)
            {
                int index =
                    SceneManager.GetActiveScene().buildIndex;
                SceneManager.LoadScene(index);
            }
            return;
        }

        timeLeft -= Time.deltaTime; // seconds since last frame
        if (timeLeft <= 0f)
        {
            timeLeft = 0f;
            EndGame("Time's up! Press R");
        }
        UpdateTexts();
    }

    public void AddCoin()
    {
        if (gameOver) return;
        coins++;
        UpdateTexts();
        if (coins >= coinsToWin) EndGame("You win! Press R");
    }

    public void Lose()
    {
        if (!gameOver) EndGame("Ouch! Press R");
    }

    void EndGame(string message)
    {
        gameOver = true;
        messageText.text = message;
        Time.timeScale = 0f; // freeze movement and physics
    }

    void UpdateTexts()
    {
        scoreText.text = "Coins: " + coins + " / " + coinsToWin;
        timerText.text = "Time: " + Mathf.CeilToInt(timeLeft);
    }
}

Select the GameManager object. Its script shows three empty slots in the Inspector. Drag ScoreText, TimerText and MessageText into them. This is called assigning a reference: you tell the script exactly which object to use.

Last, teach the player about coins and spikes. Replace all the code in PlayerController with this finished version. It adds a Game slot and a method that runs when the player touches a trigger. Then drag the GameManager object into the new Game slot on the Player.

using UnityEngine;
using UnityEngine.InputSystem;

// Moves the player and reacts to coins and spikes.
public class PlayerController : MonoBehaviour
{
    [SerializeField] float speed = 6f; // units per second
    [SerializeField] GameManager game; // drag GameManager here

    InputAction moveAction;
    Rigidbody2D body;

    void Start()
    {
        moveAction = InputSystem.actions.FindAction("Move");
        body = GetComponent<Rigidbody2D>();
    }

    void FixedUpdate()
    {
        Vector2 input = moveAction.ReadValue<Vector2>();
        body.linearVelocity = input * speed;
    }

    // Runs when the player starts touching a trigger.
    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("Coin"))
        {
            game.AddCoin();
            Destroy(other.gameObject); // remove the coin
        }
        else if (other.CompareTag("Spike"))
        {
            game.Lose();
        }
    }
}
The game loop of Coin Rush Three boxes from left to right. Start counts the coins and sets the timer. Playing is where you move, grab coins and the timer counts down. Game over shows a win when all coins are collected, or a loss when time runs out or you touch a spike. A dashed arrow from Game over back to Start is labelled: press R to unfreeze and reload the scene. 1. Start count the coins set timer to 30 2. Playing move and grab coins timer counts down 3. Game over all coins: you win time or spike: you lose press R: unfreeze and reload the scene
Coin Rush in three states. Almost every small game follows this start, play, game over loop.

Press Play and test all three endings. Time.timeScale sets the game speed: 0 freezes everything, and Start sets it back to 1 after each restart. If restarting says the scene couldn't be loaded, add it to the Scene List as shown in the next step.

Step 4: Build your game for PC

A build is a standalone copy of your game that runs without Unity.

  1. Save the scene with Ctrl+S (Cmd+S on a Mac).
  2. Open File > Build Profiles. In the Platforms list, select your computer's platform, such as Windows. If it isn't marked Active, click Switch Platform.
  3. Check the Scene List. Your scene must be listed and ticked. If it isn't, click Add Open Scenes.
  4. Name your game. Open Edit > Project Settings > Player. Set the Company Name and Product Name, and add an icon if you have one.
  5. Click Build and make a new, empty folder called Builds next to your Assets folder, not inside it.

On Windows you get an .exe file plus a few folders next to it. The game needs all of them, so zip the whole folder to share it. If a folder name ends in DoNotShip, leave that one out. Unity Personal lets you switch off the "Made with Unity" splash screen in Unity 6, under Player > Splash Image. The official build profiles page explains every option.

Common beginner mistakes (and quick fixes)

What you seeLikely causeFix
The player falls off the screen.Gravity is on.Set Gravity Scale to 0.
The player spins after hitting a wall.Rotation isn't locked.Tick Freeze Rotation Z.
Coins don't disappear.Is Trigger is off, or the tag is misspelled.Tick Is Trigger and set the tag to Coin.
Unity won't let you attach a script.There is a compile error.Fix the red Console errors first.
NullReferenceException or UnassignedReferenceException.An Inspector slot is empty.Drag the right object into the slot.
InvalidOperationException about UnityEngine.Input.The code is from an old tutorial.Use the Input System code from this guide.
A warning that velocity is obsolete.The code was written before Unity 6.Use linearVelocity instead.

If you must run old input code, set Active Input Handling to Both under Edit > Project Settings > Player > Other Settings, and let Unity restart. Learning the new way is better in the long run.

The biggest mistake isn't technical: starting with a dream game, like an open-world RPG, and quitting after a month. Finish tiny games first.

What to learn next

Still choosing an engine? Read Godot vs Unity vs Unreal Engine. For ideas, browse the indie games made with Unity that players rank on Mutop100.

FAQ

Is Unity free for beginners?

Yes. Unity Personal is free while your revenue and funding stay at or below 200,000 US dollars a year, as of November 2026. Check Unity's pricing page for the current rules.

Do I need to know coding to make a game in Unity?

No, you can start without it. You do need a little C# for game rules, but you learn it as you go. Copy small scripts, change one value at a time, and read what each line does.

How long does it take to make a game in Unity?

A tiny game like Coin Rush takes a weekend. A small, polished game usually takes one to three months of spare time. Large games take teams several years.

Can my computer run Unity 6?

Most computers from the last few years can. You need Windows 10 or 11, macOS 13 or newer, or Ubuntu 22.04 or 24.04, and Unity recommends 8 GB of RAM. Small 2D games run fine on modest laptops.

Which Unity version should a beginner use?

Use the newest Unity 6 version marked LTS in Unity Hub, which was Unity 6.3 LTS in November 2026. LTS versions get bug fixes for two years. Keep the same version for the whole project.

How old do you have to be to use Unity?

You must be old enough to consent to data processing in your country, such as 13 in the US or up to 16 in the EU. Buying anything from Unity requires being 18 or having a parent's permission. Younger beginners can use Unity with a parent's help.

Show players what you made

When your first Unity game grows into something you're proud of, list it free in the Mutop100 indie games directory with a trailer, store links and player votes.

List your game free
← 返回 MU Online 攻略