---
title: "Lab 4 - Basic Gameplay"
content_type: tutorial
url: "https://learn.unity.com/tutorial/lab-4-basic-gameplay?language=en"
language: en
difficulty: beginner
unity_version:
  - "6.0"
  - "6.3"
supported_unity_versions:
  - name: "6.0"
    url: "https://learn.unity.com/tutorial/lab-4-basic-gameplay.md?language=en&version=6.0"
  - name: "6.3"
    url: "https://learn.unity.com/tutorial/lab-4-basic-gameplay.md?language=en&version=6.3"
  - name: "2022.3"
    url: "https://learn.unity.com/tutorial/lab-4-basic-gameplay.md?language=en&version=2022.3"
  - name: "2021.3"
    url: "https://learn.unity.com/tutorial/lab-4-basic-gameplay.md?language=en&version=2021.3"
last_updated: "2026-08-04T14:25:04.000Z"
---

# Lab 4 - Basic Gameplay

Configure non-player objects with basic movement, collisions, and prefab spawning to establish your game’s core gameplay behavior.

**Overview:**

In this lab, you will work with all of your non-player objects in order to bring your project to life with its basic gameplay. You will give your projectiles, pickups, or enemies their basic movement and collision detection, make them into prefabs, and have them spawned randomly by a spawn manager. By the end of this lab, you should have a glimpse into the core functionality of your game.

**Project Outcome:**

Non-player objects are spawned at appropriate locations in the scene with basic movement. When objects collide with each other, they react as intended, by either bouncing or being destroyed.

## Give objects basic movement

> Before you spawn objects into your scene, they should move the way you want.

[Video](https://connect-mediagw.unity.com/h1/20241209/videos/7429eb96-f1a0-42dd-bbc8-d7c4ff5a361c_CWC_Lab4.S1_U6.mp4) ([Transcript (en)](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/ff74bd80-3b4f-4562-93ba-1d811e192a5a/versions%5B_key==%223c6918da5f68%22%5D.sections%5B_key==%22iEzOKWCMcO9HfjP9vvbTcf%22%5D.body%5B_key==%22iEzOKWCMcO9HfjP9vvbTfH%22%5D.subtitles/CWC_Lab4.S1_U6.mp4_20260505_050211.srt))

1. If relevant, add **Rigidbody** components to your non-player objects
2. Create a **new script**(s) for the objects that will be instantiated during gameplay and attach them to their respective objects (including projectiles or pickups)
3. Program the **basic movement** for your objects and test that they work

By the end of this step, all objects should basically move the way they should in the game.

## Destroy objects off-screen

To make sure our hierarchy doesn’t get too cluttered, let’s make sure these objects get destroyed when they leave the screen.

[Video](https://connect-mediagw.unity.com/h1/20241209/videos/795b1cd3-b561-4d11-b74d-c4b30da426f7_CWC_Lab4.S2_U6.mp4) ([Transcript (en)](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/ff74bd80-3b4f-4562-93ba-1d811e192a5a/versions%5B_key==%223c6918da5f68%22%5D.sections%5B_key==%22iEzOKWCMcO9HfjP9vvbTux%22%5D.body%5B_key==%22iEzOKWCMcO9HfjP9vvbTxZ%22%5D.subtitles/CWC_Lab4.S2_U6.mp4_20260505_050228.srt))

1. Either create a new script or add code to your existing script to make sure objects are destroyed when they leave the screen

By the end of this step, objects should be removed from the hierarchy when they are no longer in play.

## Handle object collisions

Now that you have all these moving objects, they’re bound to start colliding with each other - we need to program what should happen when everything collides.

[Video](https://connect-mediagw.unity.com/h1/20241209/videos/faea8112-a9b6-4d98-9fcd-abc09b3be66c_CWC_Lab4.S3_U6.mp4) ([Transcript (en)](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/ff74bd80-3b4f-4562-93ba-1d811e192a5a/versions%5B_key==%223c6918da5f68%22%5D.sections%5B_key==%22iEzOKWCMcO9HfjP9vvbU2n%22%5D.body%5B_key==%22iEzOKWCMcO9HfjP9vvbU5P%22%5D.subtitles/CWC_Lab4.S3_U6.mp4_20260505_050245.srt))

1. If relevant, edit the **Rigidbody mass** of your objects
2. If relevant, to change the way your objects collide, create a new **Physics material** for your objects
3. Add **tags** to your objects so you can accurately test for which objects are colliding with which
4. Use **_OnCollisionEnter()_** (for Rigidbody collisions) or **_OnTriggerEnter()_** (for trigger-based collisions) to **Destroy** or **Log** messages to the console what should happen when certain collisions occur

By the end of this step, objects should destroy, bounce, or do nothing based on collisions.

## Make objects into prefabs

Now that the objects are basically behaving the way they should, if they’re going to be instantiated during gameplay, they need to be prefabs

[Video](https://connect-mediagw.unity.com/h1/20241219/videos/295dce69-b5c0-495e-bacb-e624933753b2_CWC_Lab4.S4_U6.mp4) ([Transcript (en)](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/ff74bd80-3b4f-4562-93ba-1d811e192a5a/versions%5B_key==%223c6918da5f68%22%5D.sections%5B_key==%22iEzOKWCMcO9HfjP9vvbUWq%22%5D.body%5B_key==%22iEzOKWCMcO9HfjP9vvbUZS%22%5D.subtitles/CWC_Lab4.S4_U6.mp4_20260505_050307.srt))

1. In the Assets directory, create a new **Folder** called “Prefabs”
2. **Drag** in each object to create a **new prefab** for it
3. After all objects have been turned into prefabs, **delete** them from the scene
4. **Test** the objects’ behavior by dragging them from the Prefabs folder into the scene while the game is running

By the end of this step, all objects that will be spawned during gameplay should be prefabs and should no longer be in your scene.

## Make SpawnManager spawn Prefabs

Now that we have all of our prefabs set up, we can create a spawn manager to spawn them at intervals and, if we want, in random locations.

[Video](https://connect-mediagw.unity.com/h1/20241209/videos/572680e7-9f98-458a-b94d-0a0e6093ab1b_CWC_Lab4.S5_U6.mp4) ([Transcript (en)](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/ff74bd80-3b4f-4562-93ba-1d811e192a5a/versions%5B_key==%223c6918da5f68%22%5D.sections%5B_key==%22iEzOKWCMcO9HfjP9vvbUvf%22%5D.body%5B_key==%22iEzOKWCMcO9HfjP9vvbUyH%22%5D.subtitles/CWC_Lab4.S5_U6.mp4_20260505_050321.srt))

1. Create an Empty “Spawn Manager” object and attach a new SpawnManager.cs script to it
2. Create individual **GameObject** **or GameObject array** variables for your prefabs, then **assign** them in the inspector
3. Use the **_Instantiate()_**, **_Random.Range()_**, and the **_InvokeRepeating()_** methods to spawn objects at intervals (random objects, random locations, or both)
4. Right-click on your _Assets folder > **Export Package**_ then save a new version in your **Backups** folder

By the end of this step, objects should be spawned automatically from the appropriate location.

## Recap

## New functionality:

- Non-player objects prefabs have basic movement
- Objects are destroyed when they leave the screen
- Collisions between objects are handled appropriately
- Objects are spawned at the appropriate locations on time-based intervals

## New concepts & skills:

- Creating basic gameplay for a project independently
