COIT20271 · CQUniversity

Mobile Game
Development
with Unity

Weeks 1 & 2 — Getting Started

From installation to your first interactive game environment

UNITY Object Scene Asset
1
Week 01

Introduction to
Game Development

Setting up Unity, exploring the editor interface, and understanding the core building blocks of every game.

2
Week 1 · Introduction

What is Game Development?

Game development is the process of designing, building, and publishing interactive experiences — combining art, code, and physics into real-time simulations.

  • Design — rules, levels, story, player mechanics
  • Programming — logic, physics, AI, user input (C#)
  • Art & Assets — models, textures, sounds, animations
  • Testing — debugging, performance, playtesting
Why Unity? Unity is the world's most popular game engine — free for students, cross-platform (Android, iOS, PC, console), and backed by a massive community and asset store.
Design Rules & Story Code C# & Logic Art Assets Test & Publish
3
Week 1 · Setup

Installing Unity — Step by Step

  1. Download Unity Hub
    Go to unity.com/download and install Unity Hub — the launcher that manages your Unity versions and projects.
  2. Sign in / Create Account
    Create a free Unity ID. Students qualify for the free Personal plan.
  3. Install a Unity Editor
    In Unity Hub → Installs → Add. Choose an LTS (Long Term Support) release for stability.
  4. Add Required Modules
    Select Android Build Support + iOS Build Support for mobile deployment.
  5. Create Your First Project
    Unity Hub → New Project → Choose template: 3D (Core) or 2D.
Projects Installs Learn Unity Hub Projects New Project 3D MyFirstGame Unity 2022.3 LTS · Modified today 2D PlatformerDemo Unity 2022.3 LTS · Modified 3 days ago Installed Editors Unity 2022.3.20 LTS Add Module Android ✓ iOS ✓ ← Unity Hub Interface
4
Week 1 · Interface

The Unity Editor Interface

Unity's editor has five key panels. Understanding each one is your first skill as a game developer.

PanelPurpose
SceneVisual workspace — build your game world here
GamePreview what the player sees at runtime
HierarchyList of all objects in the current scene
InspectorProperties of the selected object
ProjectAll your files — assets, scripts, prefabs
Tip: You can drag panels to re-arrange the layout. Unity remembers your workspace layout between sessions.
File Edit Assets GameObject Component Window Help ▶ Play Hierarchy ▾ SampleScene Main Camera Directional Light Player ▸ Environment Ground Scene Cube Ground Plane Y X Game Inspector Cube Transform Position X:0 Y:1 Z:0 Rotation X:0 Y:0 Z:0 Scale X:1 Y:1 Z:1 Mesh Renderer Box Collider Rigidbody Add Component Project Console Scenes Scripts Materials Prefabs
5
Week 1 · Coordinates

2D vs 3D Coordinate Systems

2D Space — X & Y

X Y (0,0) P x=3 y=2 (3, 2)
In 2D games, every object is placed using (X, Y) coordinates. X is horizontal, Y is vertical.

3D Space — X, Y & Z

(0,0,0) X Y Z (2,1,1) left / right up / down fwd/back
In 3D games, objects use (X, Y, Z). Z is the depth axis — forward and backward in the world. Unity uses a left-handed coordinate system.
6
Week 1 · Core Concepts

Game Objects & Assets

Game Objects are the fundamental building blocks of every Unity scene. Everything in your game is a GameObject — characters, lights, cameras, terrain, UI elements.

What makes up a GameObject?

Transform — Every object has a position (X,Y,Z), rotation, and scale. It's the only built-in component.
Components — Modules attached to add behaviour: Mesh Renderer (makes it visible), Collider (physical boundary), Rigidbody (physics).
Scripts (C#) — Your own code attached as a component to give the object custom logic.

Component Architecture

GameObject e.g. "Player" Transform Position · Rotation · Scale Mesh Renderer Makes it visible Box Collider Physics boundary Rigid body Gravity & force PlayerController.cs Custom C# Script Save as Prefab = reusable template of any GameObject
7
Week 1 · Revision Activities

Week 1 — What to Do

Activity 1

Install Unity

  1. Download & install Unity Hub from unity.com
  2. Install the latest LTS Editor version
  3. Add Android Build Support module
  4. Create a new 3D Core project
Activity 2

Explore the UI

  • Identify the 5 panels in the editor
  • Navigate the Scene view — pan, zoom, orbit
  • Add a Cube via GameObject → 3D Object
  • Select it and read its Transform in the Inspector
  • Change its Position X to 3 — watch it move
Activity 3

GameObjects & Coordinates

  • Add a Sphere and a Plane to the scene
  • Place the Sphere at (0, 2, 0) — above the plane
  • Press ▶ Play and see gravity act on the sphere
  • Add a Rigidbody component and re-test
Checkpoint: Can you explain what X, Y, Z mean in your scene?
8
Week 02

Materials, Textures
& Terrain

Bring your world to life — apply visual surfaces, paint the ground, grow forests, and run your first playable game environment.

9
Week 2 · Visuals

Materials & Textures

A Material defines how a surface looks. A Texture is the image "wrapped" onto that surface — like putting wallpaper on a box.

The Rendering Chain

Texture .png / .jpg maps to Material Shader + props applied to GameObject Mesh Renderer 👁

Key Properties of a Material

PropertyEffect
AlbedoBase colour / texture map
MetallicHow shiny/metallic the surface is (0–1)
SmoothnessMirror-like vs rough surface
Normal MapFake surface bumps without extra geometry
EmissionMakes the surface glow (like neon signs)

How Textures Wrap onto Geometry

Texture (2D) wrapped onto → Textured Cube (Mesh Renderer applied)
10
Week 2 · Hands-on

Applying Materials to Game Objects

Follow these steps to create a material and apply it to any 3D object in your scene.

  1. Create a Material
    Right-click in the Project panel → Create → Material. Name it (e.g. "WoodMat").
  2. Set the Albedo Texture
    Click your new material in Project. In the Inspector, click the square next to Albedo and select a texture image (.png or .jpg).
  3. Adjust Properties
    Tune Metallic and Smoothness sliders. For wood — low metallic (0), medium smoothness (0.3).
  4. Apply to GameObject
    Drag the material from the Project panel directly onto the object in the Scene view, or assign it via the Mesh Renderer component in the Inspector.
  5. Tile the Texture
    If the texture looks too zoomed in or out, change Tiling X / Y values in the material — higher = smaller, repeating tiles.
Asset Store shortcut: Window → Asset Store. Search "free textures" for ready-made brick, wood, metal, grass, and more.

Before & After

BEFORE No material (default grey) AFTER Brick material applied ✓ Tiling Effect Tiling = 1 Tiling = 4 Higher tiling = smaller, repeated texture
11
Week 2 · Environment

Creating Terrain

Unity's Terrain system lets you "sculpt" large outdoor environments — hills, valleys, cliffs — by painting directly in the Scene view, no modelling software needed.

How to Create a Terrain

  1. Add Terrain Object
    GameObject → 3D Object → Terrain. A flat 1000×1000 unit plane appears.
  2. Raise / Lower Ground
    Select the Terrain → Inspector → Terrain ToolsRaise or Lower brush. Paint hills and valleys by clicking & dragging.
  3. Smooth the Surface
    Switch to the Smooth Heights brush to remove harsh edges.
  4. Paint Texture Layers
    Add terrain layers (grass, dirt, rock) and paint them with the Paint Texture tool.
Terrain Layers: Each layer holds a texture + normal map. Paint multiple layers to blend grass into dirt at riverbanks, or rock on steep slopes.
Terrain Cross-Section Sky / Skybox Grass Layer Dirt / Soil Layer Rock Bedrock 🖌 Brush Terrain Brush Types Raise/Lower Sculpt hills and valleys Smooth Soften harsh edges Paint Texture Add grass / rock / dirt Then add Trees & Grass → next slide
12
Week 2 · Environment

Populating Terrain — Trees & Grass

The Terrain system lets you paint trees and grass directly onto the terrain surface — thousands of instances with a single brush stroke.

Adding Trees

  1. Select Terrain → Inspector → Paint Trees tool (tree icon)
  2. Click "Edit Trees"Add Tree → drag a tree prefab from the Project panel
  3. Adjust Brush Size, Tree Density, and Random Height/Width for natural variation
  4. Click and drag on the terrain to paint a forest

Adding Grass & Details

  1. Switch to Paint Details tool (grass icon)
  2. Click "Edit Details"Add Grass Texture or Add Detail Mesh
  3. Paint grass onto the terrain surface. Wind zone can make it sway!
Performance tip: Unity uses Level of Detail (LOD) — distant trees render as billboards (flat images) to save GPU power, automatically.
Paint Trees Brush Terrain populated with trees & grass
13
Week 2 · Resources

The Unity Asset Store

The Unity Asset Store is an online marketplace of ready-made art, scripts, sounds, and tools. You don't need to build everything from scratch.

How to Access

  1. In Unity Editor: Window → Asset Store (opens in browser at assetstore.unity.com)
  2. Sign in with your Unity ID, search for what you need
  3. Click "Add to My Assets" (for free items) or purchase
  4. Back in Unity: Window → Package Manager → My Assets → Download & Import

What to Search For (This Week)

"Terrain Textures"
Ground, rock, sand
"Vegetation"
Tree & grass packs
"Skybox"
Realistic sky domes
"Environment"
Outdoor scene packs
Filter tip: Use Price → Free filter. The free tier has thousands of high-quality assets for student projects.
Asset Store Search assets... Search Free ✓ 3D ▾ Rating ▾ Forest Pack Trees & Vegetation ★★★★★ FREE Import Terrain Tex Ground Textures ★★★★☆ FREE Import Skybox Series Day / Night Sky ★★★★★ FREE Import Environment Starter Kit ★★★★☆ FREE Import assetstore.unity.com
14
Week 2 · Play Mode

Test Run Your First Game Environment

Unity's Play Mode lets you test your game inside the editor — no build needed. The Game view shows exactly what the player would see.

The Play / Pause / Step Controls

▶ Play ⏸ Pause ⏭ Step frame by frame
Important: Changes made during Play Mode are NOT saved. Unity resets everything when you stop. Test, then stop, then make changes.

Intermediate Functions to Try

  • Camera positioning — Move the Main Camera to frame your terrain beautifully. Try Component → Align with View.
  • Directional Light — Rotate the sun light to create morning/dusk atmosphere
  • Wind Zone — Add via GameObject → Effects → Wind Zone. Grass and trees will sway
  • Fog — Window → Rendering → Lighting → Environment → Enable Fog for depth
Scene Game ✓ Game View (1920×1080) FPS: 120 Tris: 24.2K Draw: 18 ▶ Play Mode Active — Terrain with trees & grass rendering Intermediate: try adjusting Fog, Light angle & Wind Zone Remember: Stop ▶ before making permanent changes
15
Week 2 · Revision Activities & Learning Outcomes

Week 2 — What to Do

Activity 1

Textures & Materials

  1. Create 3 materials: metal, wood, grass
  2. Import textures (from Asset Store or provide your own .png)
  3. Apply each material to a different primitive GameObject
  4. Adjust Smoothness & Tiling for each
Activity 2

Build Your Terrain

  1. Add a Terrain to a new scene
  2. Sculpt at least one hill and one valley
  3. Paint 2 texture layers (e.g., grass + dirt)
  4. Proliferate with trees & grass
  5. Press ▶ and play your environment!
Activity 3

Intermediate Functions

  • Browse the Unity Asset Store — add one free asset to your project
  • Enable Fog in the Lighting settings
  • Add a Wind Zone and see grass sway
  • Position the Main Camera for a cinematic game-start shot
By End of Week 2

Learning Outcomes

  • Apply intermediate Unity functions (wind, fog, camera)
  • Access and search the Unity online Asset Store
  • Test run and play your first game environment ✓
Next Up — Week 3: Scripting with C# — bringing objects to life with custom behaviour and player controls.
16
Practical · Game Plan

What We're Building — "Roll & Collect"

A complete 3D mobile-ready game built step by step. By the end you will have a real, playable game you built yourself from scratch.

Game Features

  • Player ball — rolls with keyboard/touch input using physics
  • 12 collectibles — rotating gems that disappear on contact
  • Score counter — live HUD showing your progress
  • Win screen — triggered when all gems collected
  • Sound effects — pickup sound and win fanfare
  • Particle effect — burst on collection

What You'll Learn

C# Scripting
Input, physics, collision, UI
Prefabs
Reusable game objects
UI Canvas
Score text on screen
Audio & Particles
Polish & juice
PLAYER ★ Collectibles ★ Score: 7 / 12 Progress bar Build Steps (this section) ① Scene Setup — ground & walls ② Player — ball + Rigidbody physics ③ C# Script — keyboard movement ④ Camera — smooth follow ⑤ Collectibles — prefab + rotation ⑥ Score UI — Canvas + Text ⑦ Win screen + Sound + Particles
17
Step 1 · Scene Setup

Step 1 — Build the Playing Field

Create a new 3D Core project. We'll build an enclosed arena — a flat ground and four walls to keep the ball in bounds.

Create the Ground

  1. GameObject → 3D Object → Plane
    Rename it "Ground" in the Hierarchy
  2. In Inspector → Transform → Scale: (2, 1, 2)
    This makes a 20×20 unit ground plane
  3. Create a Green material → assign to Ground

Create the Walls (repeat × 4)

  1. GameObject → 3D Object → Cube → rename "Wall West"
  2. Set Transform values from table below
  3. Duplicate (Ctrl+D) and adjust for each wall
WallPositionScale
West(-10, 0.5, 0)(0.5, 1, 20)
East(10, 0.5, 0)(0.5, 1, 20)
North(0, 0.5, 10)(20, 1, 0.5)
South(0, 0.5, −10)(20, 1, 0.5)
Organise: Select all 4 walls → Right-click Hierarchy → Create Empty Parent → name it "Walls". Keeps things tidy.
Arena — Top View Ground Scale (2,1,2) = 20×20 units Wall West Wall East Wall North Wall South ▾ SampleScene Main Camera Ground ▸ Walls (4 children)
18
Step 2 · Player Object

Step 2 — Create the Player Ball

  1. Add a Sphere
    GameObject → 3D Object → Sphere
    Rename to "Player" in Hierarchy
  2. Set its position
    Position: (0, 0.5, 0) — sits on top of the ground
  3. Add a Rigidbody
    Inspector → Add Component → Physics → Rigidbody
    This gives the ball mass and responds to gravity & forces.
  4. Create a Player material
    Make a red/orange material and drag it onto the sphere
Why Rigidbody? Without it, pushing a sphere would make it pass through walls. Rigidbody hands control to Unity's physics engine — it handles gravity, collisions, and momentum automatically.
Sphere Collider — Already built in to the Sphere! You can see it in the Inspector under the Rigidbody. It defines the physical boundary the engine uses for collisions.
Inspector Player Static ▾ ▾ Transform Position X 0 Y 0.5 Z 0 Rotation X 0 Y 0 Z 0 Scale X 1 Y 1 Z 1 ▾ Sphere Collider Is Trigger ☐ Radius 0.5 ▾ Rigidbody ← ADD THIS Mass 1 Drag 0 Use Gravity ☑ Is Kinematic ☐ Add Component Player sphere in scene
19
Step 3 · C# Scripting

Step 3 — Write the PlayerController Script

Scripts give your GameObjects behaviour. Attach this script to the Player sphere to allow keyboard-controlled movement using physics forces.

  1. In Project panel → right-click → Create → C# Script → name it PlayerController
  2. Double-click to open in Visual Studio / VS Code
  3. Replace the code with the script shown →
  4. Save the file, then drag the script onto the Player in the Hierarchy
  5. In Inspector, set Speed = 10 in the script component
Input.GetAxis("Horizontal") returns −1 (left), 0 (still), or +1 (right). Same for Vertical. Arrow keys and WASD both work automatically.
rb.AddForce() applies a physics force to the ball — it accelerates, slows with friction, and bounces off walls naturally. Much better than moving position directly!
// PlayerController.cs
using UnityEngine;

public class PlayerController : MonoBehaviour
{
  public float speed = 10f;
  private Rigidbody rb;

  void Start()
  {
    // Get Rigidbody once at start
    rb = GetComponent<Rigidbody>();
  }

  void FixedUpdate()
  {
    // Read keyboard/gamepad input
    float h = Input.GetAxis("Horizontal");
    float v = Input.GetAxis("Vertical");

    // Build movement vector
    Vector3 move = new Vector3(h, 0f, v);

    // Push the ball with physics force
    rb.AddForce(move * speed);
  }
}
Press ▶ Play now! Use WASD or arrow keys. The ball should roll around the arena. Adjust speed in the Inspector while playing to tune feel.
20
Step 3 · Concept

Update() vs FixedUpdate() — Why it Matters

Two of the most important methods in Unity. Understanding when to use each prevents buggy physics and choppy movement.

Update()

Runs every rendered frame. If your game runs at 60fps, Update runs 60× per second. At 30fps, it runs 30×. The rate is variable.


✅ Use for: input reading, moving non-physics objects, UI updates, spawning things

❌ Avoid: physics forces — inconsistent results at different framerates

FixedUpdate()

Runs at a fixed rate (default: 50× per second, regardless of framerate). Physics simulation is synced to this.


✅ Use for: Rigidbody.AddForce(), velocity changes, anything physics-related

Result: smooth, consistent physics on any device speed

Frame Timeline Comparison time → Update() Variable (60fps shown) Inconsistent intervals — bad for physics! FixedUpdate() Fixed every 0.02s (50/sec) Perfectly even intervals — physics stays stable Common Unity Lifecycle Methods Awake() First ever, before Start Start() Once at scene begin Update() Every frame FixedUpdate() Physics step OnTriggerEnter() On collision OnDestroy() Object removed
21
Step 4 · Camera

Step 4 — Smooth Camera Follow

Right now the camera is fixed. We want it to follow the player smoothly — always behind and above the ball, maintaining a constant offset.

  1. Create a new C# Script → name it CameraController
  2. Attach it to the Main Camera in the Hierarchy
  3. Enter the code shown →
  4. In the Inspector on the Camera, drag the Player sphere into the "Player" field
The offset trick: We record the difference between camera and player positions in Start(). Then in LateUpdate we just add that offset back every frame — the camera stays at the exact same relative position forever.
LateUpdate() runs after all Update() calls finish — perfect for cameras, so the player has already moved before we reposition the camera. Prevents jitter.
// CameraController.cs
using UnityEngine;

public class CameraController : MonoBehaviour
{
  public GameObject player;
  private Vector3 offset;

  void Start()
  {
    // Record the gap at game start
    offset = transform.position
           - player.transform.position;
  }

  void LateUpdate()
  {
    // Maintain the same offset
    transform.position =
      player.transform.position + offset;
  }
}
Side View — Camera Offset Player Camera offset
22
Step 5 · Prefabs

Step 5 — Create Collectible Gems (Prefabs)

We'll make one gem, make it spin, turn it into a Prefab (reusable template), then place 12 copies around the arena.

Build One Gem

  1. GameObject → 3D Object → Cube → rename "PickUp"
    Scale: (0.5, 0.5, 0.5)   Rotate Y: 45°
  2. Create a bright yellow material → assign to the cube
  3. Inspector → Add Component → Rigidbody
    ⚠️ Uncheck Use Gravity — it floats!
  4. On the Box Collider, tick Is Trigger — this lets the ball pass through while still detecting contact
  5. Add Component → New Script → name it RotateGem (see code below)
// RotateGem.cs
void Update() {
  transform.Rotate(new Vector3(15, 30, 45) * Time.deltaTime);
}

Make it a Prefab & Place 12 Copies

  1. Drag the PickUp object from Hierarchy into a "Prefabs" folder in Project
  2. Delete the original. Now drag the Prefab into the scene 12 times
  3. Scatter them around the arena — change their X and Z positions
Prefab = Reusable Template PickUp.prefab Cube · Trigger · Rotate stored in /Assets/Prefabs/ Instance ×1 Instance ×2 Instance ×3 ... Why Use Prefabs? • Change the master prefab → ALL instances update • Spawn objects at runtime via Instantiate(prefab) • Reuse across multiple scenes without copy-pasting • Identified by blue text in the Hierarchy panel Scatter 12 Gems in Your Arena × 12 collectible gems placed
23
Step 6 · Collision Detection

Step 6 — Detect Collisions & Count Score

When the ball touches a gem, we want to: destroy the gem, increase the score, and check if the player has won. All of this goes in the PlayerController script.

Tag the gems first! Select all PickUp instances → Inspector → Tag dropdown → Add Tag → create PickUp. Then assign it. This lets code identify gems specifically.
OnTriggerEnter fires when another Collider enters our Trigger zone. We check the tag to make sure it's a gem (not a wall) before collecting.
Destroy(other.gameObject) removes the gem from the scene permanently. The score int is then incremented and sent to the UI.
using UnityEngine;
using UnityEngine.UI;
using TMPro; // ← add this, remove UnityEngine.UI if you want

public class PlayerController : MonoBehaviour
{
  public float speed = 10f;
  private Rigidbody rb;

  public TMP_Text scoreText; // ← was: public Text scoreText
  public TMP_Text winText; // ← was: public Text winText
  private int score = 0;
  private int totalGems = 12;

  void Start()
  {
    rb = GetComponent<Rigidbody>();
    winText.text = "";
    UpdateScore();
  }

  void FixedUpdate()
  {
    float h = Input.GetAxis("Horizontal");
    float v = Input.GetAxis("Vertical");
    Vector3 move = new Vector3(h, 0f, v);
    rb.AddForce(move * speed);
  }

  void OnTriggerEnter(Collider other)
  {
    if (other.gameObject.CompareTag("PickUp"))
    {
      Destroy(other.gameObject);
      score++;
      UpdateScore();
    }
  }

  void UpdateScore()
  {
    scoreText.text = "Gems: " + score;
    if (score >= totalGems)
    {
      winText.text = "You Win! 🎉";
    }
  }
}
24
Step 7 · UI System

Step 7 — Build the Score HUD with UI Canvas

Unity's UI Canvas is a special layer that always renders on top of the game world — perfect for HUDs, menus, and score displays.

Create the Canvas & Text

  1. GameObject → UI → Canvas
    A Canvas appears in Hierarchy. Set UI Scale Mode: Scale with Screen Size in the Canvas Scaler component.
  2. Right-click Canvas → UI → Text - TextMeshPro
    Name it "Score Text". Install TMP Essentials if prompted.
  3. In Rect Transform: Anchor top-left, Pos X: 20, Pos Y: −20
    Set font size 28, colour white, text: Gems: 0
  4. Duplicate → rename "Win Text", anchor centre, font size 48, colour yellow, empty text
  5. Select Player → drag Score Text and Win Text into the script fields in Inspector
Note: Use using TMPro; and TMP_Text instead of Text if using TextMeshPro — it's higher quality and the modern Unity standard.
Gems: 3 You Win! 🎉 Score Text (TMP) Hierarchy ▾ SampleScene Main Camera Player ← PlayerController.cs Ground ▸ Walls ▸ PickUps (12 gems) ▾ Canvas   Score Text   Win Text
25
Step 8 · Audio

Step 8 — Add Sound Effects

Sound makes games feel alive. We'll add a pickup chime when collecting a gem and a win fanfare when all gems are collected.

Setup

  1. Import audio files — drag .wav or .mp3 files into your Project Assets folder
    Free sounds: freesound.org or Unity Asset Store
  2. Select the Player → Add Component → Audio → Audio Source
    Uncheck Play On Awake — we control when it plays
  3. Add two AudioClip fields to PlayerController and wire them in Inspector
AudioSource is the "speaker" on the GameObject. AudioClip is the sound file. Call audioSource.PlayOneShot(clip) to play without interrupting other sounds.
3D vs 2D Sound: In the Audio Source component, set Spatial Blend to 0 for UI-style sounds (same volume everywhere) or 1 for 3D positional audio that fades with distance.
// Add to PlayerController.cs

public AudioSource audioSrc;
public AudioClip pickupSound;
public AudioClip winSound;

// Inside OnTriggerEnter:
audioSrc.PlayOneShot(pickupSound);

// Inside UpdateScore when won:
audioSrc.PlayOneShot(winSound);
Audio Signal Flow AudioClip .wav / .mp3 AudioSource on Player Speakers 🔊 Output Pickup sound waveform PlayOneShot() plays over existing audio Spatial Blend: 0 = 2D (HUD) · 1 = 3D (world)
26
Step 9 · Polish

Step 9 — Particle Burst on Collection

A particle burst when you collect a gem makes the game feel juicy. Unity's Particle System handles hundreds of tiny animated sprites.

Create the Particle Effect

  1. GameObject → Effects → Particle System
    Rename "GemBurst". This is your master effect.
  2. In the Particle System Inspector:
    • Duration: 0.5 · Loop: off
    • Start Lifetime: 0.5 · Start Speed: 4
    • Start Size: 0.2 · Start Color: Yellow
    • Emission → Bursts: Count 20 at Time 0
  3. Enable Stop Action: Destroy so the effect cleans itself up
  4. Drag to Prefabs folder → then delete from scene
  5. In PlayerController: add a public GameObject gemBurstPrefab field, assign it in Inspector
// In OnTriggerEnter, after Destroy():
Vector3 pos = other.transform.position;
Instantiate(gemBurstPrefab, pos,
           Quaternion.identity);
Particle Burst Effect Before After (burst!) +1 gem ✓ Particle System — Inspector Duration0.5 LoopOFF Start Lifetime0.5 Start Speed4 Start Size0.2 Start Color Burst Count20 @ t=0 Stop ActionDestroy ShapeSphere ★ Save as Prefab then Instantiate()
27
Step 10 · Mobile Build

Step 10 — Build & Deploy to Android

Add Mobile Touch Input

Before building, swap keyboard input for a joystick using Unity's Input System package (or a free virtual joystick from the Asset Store).

Quick solution: Window → Package Manager → Unity Registry → search "Input System" → Install. Then use the Touchscreen class, or add a Virtual Joystick Asset Store package for a plug-and-play UI stick.

Build Settings

  1. File → Build Settings
    Select Android → click Switch Platform (Unity recompiles)
  2. Player Settings (bottom-left button)
    Company Name, Product Name, Bundle ID: com.yourname.rollcollect
  3. Minimum API Level → Android 8.0 (API 26) for broad device coverage
  4. Enable Developer Mode on your Android phone. Connect via USB. Enable USB Debugging in phone settings.
  5. Build & Run → choose your connected device → Unity compiles and installs the APK directly on your phone!
Build Pipeline File → Build Settings Select Android → Switch Platform Player Settings Bundle ID · Min API · Icons Connect Android Phone USB + Developer Mode + USB Debug Build & Run ▶ Compiles → installs .apk on device Gems: 2 Game live on device! ✓
28
Complete Game — Build Checklist

Your Complete "Roll & Collect" Game

Scene & Environment

  • ☐ Ground plane (20×20)
  • ☐ 4 enclosing walls
  • ☐ Directional light (sun)
  • ☐ Green material on ground
  • ☐ Skybox set (Window → Lighting)

Player

  • ☐ Sphere at (0, 0.5, 0)
  • ☐ Rigidbody component
  • ☐ PlayerController.cs attached
  • ☐ Speed = 10 in Inspector
  • ☐ AudioSource attached

Camera

  • ☐ CameraController.cs on Main Camera
  • ☐ Player dragged into Camera script field
  • ☐ Camera positioned above & behind ball

Collectibles

  • ☐ PickUp prefab (Cube, 0.5 scale)
  • ☐ Rigidbody — No Gravity
  • ☐ Box Collider — Is Trigger ✓
  • ☐ RotateGem.cs attached
  • ☐ Tag = "PickUp"
  • ☐ 12 copies placed in arena

UI & Score

  • ☐ Canvas (Scale with Screen Size)
  • ☐ Score Text (top-left)
  • ☐ Win Text (centre, blank)
  • ☐ scoreText & winText wired in Inspector

Polish

  • ☐ Pickup sound clip assigned
  • ☐ Win sound clip assigned
  • ☐ GemBurst particle prefab assigned
▶ Press Play — collect all 12 gems!
You built a complete Unity game from scratch. 🎮
29
Reference · Complete Code

Complete PlayerController.cs — Final Script

// PlayerController.cs — Full version
using UnityEngine;
using TMPro;

public class PlayerController : MonoBehaviour
{
  // ── Inspector Fields ───────────────
  public float speed = 10f;
  public TMP_Text scoreText;
  public TMP_Text winText;
  public AudioSource audioSrc;
  public AudioClip pickupSound;
  public AudioClip winSound;
  public GameObject gemBurstPrefab;

  // ── Private State ──────────────────
  private Rigidbody rb;
  private int score = 0;
  private int totalGems = 12;

  void Start() {
    rb = GetComponent<Rigidbody>();
    winText.text = "";
    UpdateHUD();
  }

  void FixedUpdate() {
    float h = Input.GetAxis("Horizontal");
    float v = Input.GetAxis("Vertical");
    Vector3 move = new Vector3(h, 0f, v);
    rb.AddForce(move * speed);
  }

  void OnTriggerEnter(Collider other) {
    if (other.gameObject.CompareTag("PickUp")) {
      Instantiate(gemBurstPrefab,
        other.transform.position, Quaternion.identity);
      Destroy(other.gameObject);
      audioSrc.PlayOneShot(pickupSound);
      score++;
      UpdateHUD();
    }
  }

  void UpdateHUD() {
    scoreText.text = "Gems: " + score
                    + " / " + totalGems;
    if (score >= totalGems) {
      winText.text = "You Win! 🎉";
      audioSrc.PlayOneShot(winSound);
    }
  }
}

What Each Section Does

Inspector Fields (public)
Appear in the Unity Inspector. Assign assets and references without touching code — great for tweaking values without a recompile.
Start()
Runs once when the game begins. Gets the Rigidbody reference and initialises the HUD to show 0 gems.
FixedUpdate()
Physics-safe update loop. Reads axis input and applies AddForce every physics step for smooth, framerate-independent movement.
OnTriggerEnter()
Called by the engine automatically when another collider enters our trigger zone. Tag check ensures only gems trigger the collect logic.
UpdateHUD()
Centralised method for score display. Called from Start and after each collection — keeps the UI always in sync with game state.
Extension ideas: Add a timer, add restart button (SceneManager.LoadScene), add power-ups, add enemy that chases you.
30