跳转至

Module 2: Bounds and Navigation

Required Skills

You need to master and practice the following skills in Unity:

  • Working with Unity Prefabs
    • Create prefabs in editor
    • Create/Delete objects at runtime
  • Continue working with GameObject Transform component
    • Set positions
    • Set object rotation/orientation
  • User Interface
    • Getting world position from mouse
  • Object collisions and responses

Core Concepts

You need to understand and master these concepts:

  • Camera and visible world bounds
  • Frame update time vs wall-clock real time
  • Randomness and simple applications in games
  • Direct object control: driving objects

Camera Bounds

Runtime Behavior

Use WASD to place arrows, randomly respawn when touching camera bounds.

Project Organization

  • Create new Scripts folder in Assets
  • Create two subfolders under Scripts:
    • Hero (supports GreenUp)
    • Utilities (contains CameraSupport)

Scene Setup

  • MainCamera: Add CameraSupport component
  • GreenUp: Add GreenArrowBehavior component

CameraSupport Script

C#
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
public class CameraSupport : MonoBehaviour 
{
    private Camera mTheCamera;
    private Bounds mWorldBound;

    // Get current world bounds
    public Bounds GetWorldBound() 
    {
        return mWorldBound;
    }

    // Check collision with world bounds
    public bool CollideWorldBound(Bounds objectBound) 
    {
        return mWorldBound.Intersects(objectBound);
    }
}

Object Navigation

Runtime Behavior

Green arrow follows mouse, or toggle to WASD control with spacebar.

Key Features

  • Public variables visible in Inspector and changeable during runtime
  • Speed: Distance per unit time
    • mHeroSpeed: units moved per second
    • mHeroRotateSpeed