🎮

Unity Game Development Lecture Notes

Jul 19, 2024

Unity Game Development Lecture Notes

Introduction

  • Mark's motivation to make video games using Unity.
  • Unity: game engine used for popular titles like Cuphead, Outer Wilds, Pokemon Diamond remake.
  • Mark's problem with long tutorials and his hands-on learning approach.

Three-Step Learning Technique

  1. Learn the absolute basics.
  2. Cement with simple exercises.
  3. Figure out the rest as you go along.
  • Mark's success: released a puzzle platformer and an interactive video essay.

Learning Unity Basics

  • Identify core needs:
    • Character movement.
    • Spawning and deleting objects.
    • Handling collisions and game over events.
    • Implementing animations and sound effects.
  • Methods: lengthy tutorials, Unity docs, Google, trial and error.

Tutorial Overview: Creating Flappy Bird

  • Objective: learn Unity by creating a game similar to Flappy Bird.
  • Steps covered: From downloading Unity to sharing the game.
  • Outcome: Understanding core Unity functions via a practical example.

Getting Started with Unity

  • Download Unity Hub: Make a free account, install Unity Editor (version 2021.3).
  • Install Visual Studio: Essential for writing programmatic code.
  • Create New 2D Project: Set up an empty project with 2D configurations.

Unity Interface and Panels

  1. Project Panel: Contains game assets (e.g., sprites, scripts, sounds, fonts).
  2. Hierarchy Panel: Lists GameObjects in the current scene (e.g., bird, pipes).
  3. Inspector Panel: Modify GameObjects' properties (e.g., position, rotation, components).
  4. Scene/Game View Panels: Visual representation of the game's current state.

Creating the Bird

  • GameObject: Invisible container with properties like position, rotation, scale.
  • Sprite Renderer: Adds visual representation to GameObject.
  • Adding Components: Transforms GameObject functionality (e.g., Rigidbody 2D for physics, Collider).

Programming in Unity

  • Scripts: Add custom components and behaviors to GameObjects.
  • Start vs. Update: Start runs once; Update runs every frame.
  • Referencing Components: Use public references to interact with GameObject components.
  • Using If Statements: Conditional logic to control behavior (e.g., movement on spacebar press).

Implementing Game Mechanics

  • Physics Object: Add Rigidbody 2D to apply gravity.
  • Collisions: Use colliders to detect interactions.
  • Code for Moving GameObjects: Adjust position based on frame rate.
  • Randomly Spawning Objects: Use timers and instantiate prefabs.

Creating UI Elements

  • Canvas: Standard Unity UI element for displaying text, images, buttons.
  • Text Component: Display score and game messages.
  • Logic Manager: Handles game logic, score tracking, UI updates.

Game Over and Restart Functionality

  • Game Over Screen: Display message and restart button.
  • Restart Function: Reloads the current scene to restart the game.

Additional Features and Challenges

  1. Game Over Conditions: Handle off-screen bird and collision-based game over.
  2. Bug Fixing: Address issues like scoring post game over.
  3. Sound Effects: Implement audio cues for actions/events.
  4. Particle System: Add visual effects (e.g., clouds).
  5. Animations: Animate GameObjects (e.g., bird's wings flapping).
  6. Title Screen: Create an initial scene before gameplay starts.
  7. High Score Saving: Use PlayerPrefs for persistent score tracking.

Expanding and Customizing the Game

  • Creative Adjustments: Add new mechanics, objectives (e.g., shooting missiles, targets).
  • Remaking Other Games: Apply learned techniques to recreate other simple games.

Final Tips

  • Learn through experimentation and self-directed problem-solving.
  • Explore changes and new methods (e.g., new Input System, TextMeshPro).
  • Join the community: share progress, seek help, watch other developers.
  • Continue learning and expanding knowledge to become proficient in game development.