CS2335
Master 1.0.0
Master 1.0.0
  • Introduction
  • Introduction
    • Introduction
      • Game Design
    • Unity - Download
    • Visual Studio - IDE
    • Unity Manual, Scripting API
  • Unity Basics
    • Unity Editor Windows
    • Behavior Components
    • 2D Project, Scenes
      • Create 2D Sprite GameObject
      • Create UI-Text GameObject
    • MonoBehavior - Base-Class
    • Create a Custom C# Script
  • Game Coding Structures
    • Games Overview
    • Unity Engine - Event Functions
    • Finite State Machines
    • UML Class Diagram
  • Animation
    • Animator Controller
    • Animation Steps
      • Optional: Dead Animation
    • PlayerController.cs V0
  • Project 1 - Player
    • Player GameObject v1
      • C# Generics, Statics
    • Player GameObject - Jump
    • PlayerController.cs V2-Jump
    • PickUp PreFabs
      • Sorting Layers
    • PlayerController.cs V3-Collide
    • GameData Version1
    • GameData Version2
    • PlayerController V4-Score
  • Project 1 Details
    • Project1 GameObjects
    • PlayerStats Version1
      • UI-Canvas
    • Utility Class
    • Simple Spawner
    • MiniGameManager
      • Logic Diagrams
      • StartButton
      • ResultsPanel
  • Project1 Enhancements
    • PickUp - SelfDestruct
    • Spawn from List of Prefabs
  • Project 2 - StateManager
    • Project 2 - Learning Objectives
      • Inspiration
        • Branching Story Structures
        • Branching Structures
        • Hero's Journey
        • Visual Novel in Unity-Links
    • Project 2 - Starter Assets
    • State Machine Framework
    • StateManager - Singleton Design Pattern
    • Interface IStateBase
    • Create SceneXState.cs
    • OptionPanel Prefab
      • UI Images: Sprite Sheets
      • Button Image-Transitions
    • Project 2 - List of Steps
    • Project 2 - Starter Code
  • Project 2 -Dialogue
    • Hide_Show_Panel Script
    • Edit OptionPanel
    • Simple DialogPrefab
    • Conversation Entry
    • SimpleDialog.cs
    • ScriptableObjects
      • Scriptable Object Factory
    • Conversation Scriptable Objects
    • DialogManager_ConvList
      • DialogManager V2
      • Coroutines: Dynamic Text
      • DialogPrefab wImage
  • Overview: Branching Logic
    • DialogTrigger
    • Dictionary Data-Structure
      • Unity PlayerPrefs Dictionary
    • GameData Version3
    • Dictionary: choiceData
      • SaveChoice, ChoicePanel
        • choiceData - examples
          • Dictionary Value to Disable Options
    • Configure UI-Button Listeners
      • NPC Animation
      • NPC Activation
    • UI-Triggered Animations
    • Simple Inventory
    • EndState Conditions
    • Script ExecutionOrder
    • Custom UnityEvents
    • PlayerStats v2
      • ModifyPlayerData
      • BuyItem
    • Text Input
  • UI Components
    • Finding Game Objects
    • Game Objects: UI vs. 2D Sprite
    • UI Elements
      • Canvas: Screen-Space Render-Mode
      • UI-Buttons To Change Scene
  • Proj4: Inventory System
    • Inventory-System
      • GameData version4
      • Install and Configure
      • Diagrams, Resources
        • Item, Gem, Potion Classes
        • Inventory Class
      • InventoryDisplay, Slot UI
        • InventoryDisplay Class
        • Slot Class
        • Hazard Class
        • Layout Groups
      • Customization Steps
        • Configure Animation
        • AddItem Button
        • Concrete Class: Food
        • MiniGame Mods
          • PlayerController Mods
      • Code: InventorySystem
        • GameData, PickUp Mods
      • Resources: Data Structures
  • Custom Unity Events
    • Event Publishing Patterns
    • Custom Event Messaging
  • Proj4: Mini-Game
    • Simplified Mini-Game
      • PlayerController_v2 Mods
        • PlayerController_v2_final
      • MiniGameManager_v2
    • MiniGame-Overview-Proj4
    • LevelManager
      • LevelManager Logic Diagram
      • LevelManager FSM
      • LoadLevel, StartLevel Logic
      • Code Framework
    • Timer
  • Project 4 - Code Mods
    • Project 4 - Steps
    • Project 4 - Code
      • Code: Final Versions
        • PlayerController Mods
          • PlayerController_v2 Mods
        • GameData - Final
        • LevelManager
        • PlayerStats - Final
        • PickUp, Hazard, ScorePickUp
        • Spawner - Final
        • CameraFollow
        • ScreenFader
        • MiniGameState
        • Example: EndState
      • MiniGameWin Logic
  • Optional, Supplemental Content
    • Optional Content
      • Particle Systems
      • Adding Audio
      • Screen Fading and Reloading
      • ScriptableObjects
      • Disable Debug Logging
      • Events and Actions
      • Saving Data - Serialization
      • Parallax Scrolling
      • Change Sprites
    • XR - Extended Reality
  • Computing Concepts
    • Programming Patterns
      • State - FSM
      • Singleton Pattern
    • C# Language
      • Variables
      • Delegates
      • Dictionary
      • Enum
      • Encapsulation
        • C# Properties
        • Access Modifiers
      • Generics < T >
      • Inheritance
      • Interface
      • List< T >
      • Polymorphism
      • Queue< T >
      • Switch-Case
      • Foreach
      • Static
      • Ternary Operator: ?
      • this
    • Diagrams
      • State Machine Framework
      • UML Class Diagrams
      • Level Manager Logic Diagram
      • Flow-Chart: NumberGame
      • FSM: NumberGame
    • Tools
    • Glossary
    • References and Resources
    • Random Thoughts
Powered by GitBook
On this page
  • Project1: MiniGame Game Objects
  • GameObjects Descriptions:
  • ToDo: Add the following GameObjects and Scripts
  • Project 1 GameObjects, Scripts
  • Steps to Create and Configure Player GameObjects:
  • Overview: Steps, Links for Other GameObjects
  • New GameObjects, Scripts

Was this helpful?

  1. Project 1 Details

Project1 GameObjects

Overview of Project1 GameObjects and C# Scripts

Project1: MiniGame Game Objects

For a simple 2D game, we'll focus on simple 2D game-mechanics and UI-display of game-stats to provide feedback to the player:

GameObjects Descriptions:

  1. Player gameObject that can be controlled by the user to interact with other objects in the game-world.

    • User-Input: Input-Events control movement, animation

    • Interaction: Collision-Events modify: Score, Health, Collected Items, etc. Logic for handling event: OnTriggerEnter2D( )

    • GroundCheck: for Jump, Layer: Ground , Floor

  2. PickUp objects: gameObjects that the Player gameObject interacts with to change the game's data.

    • Interaction: Collider2D, isTrigger, OnTriggerEnter2D( ), Collision-Events - destroy or inactivate gameObject

    • Movement - optional, add Rigidbody2D for simple falling movement (will need a 2nd, nested Collider2D to prevent from falling through the floor)

    • Value, PickupType: PickUp script component provides method to store value, PickUpType type

    • Tags: Collectible, Hazard

    • Prefabs - creates preconfigured gameObject that can be instantiated via code

  3. GameData - Singleton gameObject to store score, health, etc.

ToDo: Add the following GameObjects and Scripts

  1. User Interface - PlayerStats Display - Display changing score, health to give player feedback about game-play actions.

  2. Utility: C# Static Class with Static Methods, ex: modify CanvasGroup alpha

  3. Spawner - Script on Empty GameObject. Script will randomly instantiate PickUp prefabs.

  4. MiniGameManager - Script on Empty GameObject. Script will contain logic to Start, Restart the game and determining when the game is over due to win / lose conditional logic

    1. MiniGameState enums - manage GameState: idle, active, win, lose

    2. StartButton visibility controlled by MiniGameManager logic

      1. StartButton executes Listener Method: RestartGame( ) to set MiniGameState to MiniGameState.active

    3. ResultsPanel - visibility and text - controlled by MiniGameManager logic

      1. ResultsPanel Shows Game Conclusion Text - has CanvasGroup so is hidden when not in use

Project 1 GameObjects, Scripts

Steps to Create and Configure Player GameObjects:

  1. Player gameObject

      • Set Constraints: Freeze Rotation Z-axis

    • Add PlayerController as a Script Component to Player GameObject

    • Create, and configure Sorting Layer: Player

    • Create a Prefab from the Player gameObect

Overview: Steps, Links for Other GameObjects

    • Add one or more Physics2D > Collider2D components to create a boundary for each object

    • Set IsTrigger checkbox for these Collider2D components - will generate execution of onTriggerEnter2D( ) in PlayerController.cs

      • Add PickUp as a Script Component to each PickUp gameObject: Set the value, PickupType type in the Inspector.

    • Create Tags: Collectible, Hazard

    • Add Tag: Collectible or Hazard to each PickUp

    • Create, set custom Sorting Layer: Spawned

    • Create a Prefab from each type of PickUp object

    • Add GameData as a Script Component to new Empty GameObject named: GameManager

New GameObjects, Scripts

    1. In inspector panel, add PickUp prefabs from assets folder to the Spawner script component for GoodPrefab, BadPrefab attributes.

    1. In inspector panel, add ResultsPanel, StartButton, Spawner as attributes to the MiniGameManager script component

PreviousPlayerController V4-ScoreNextPlayerStats Version1

Last updated 4 years ago

Was this helpful?

Sorting Layers is the preferred method for ordering sprite layering for rendering.

Create

Add Component - this is required for objects that will have movement, physics forces should be used to give movement to gameObjects.

Add Components - select 1 or more Colliders to fit your gameObject. Select the Edit-collider button to change the size of the collider, manually change the x or y offset. Collider gives physical collision boundary game objects.

C# Script: Versions 1-4 - includes logic for movement, collision, update score, health

Prefabs Create Several 2D Sprite Game Objects: (objects for the player to interact with - we'll call these PickUp objects )

- Create an empty GameObject, attach a BoxCollider2D, edit the collider so it is a wide rectangle, move toward the bottom of the screen.

Create, Set custom physics Layer: (for Player jump behavior)

:

- Add Script to a UI-Panel that has 2 children: UI-Text ScoreText, UI-Text HealthText.

(Static Class) - Static class, Static methods:This script does not inherit from MonoBehaviour, it will not be put on a gameObject in any scenes. Because Utility is a static class: it's public static methods will be accessible to other scripts using the class name, and then the desired method to be executed: Utility.ShowCG( somePanel );

Create C# Script: Add Script to an Empty GameObject: Spawner,

- becomes visible to show final MiniGameState: win / lose, otherwise CanvasGroup alpha = 0, to hide panel

- functions as event-listener - executes ReStartGame(

Create C# Script: MiniGameManager, Add Script to Empty GameObject: MiniGameManager

Unity Tutorial Video on SortingLayers
Animation using Animator Controller
Physics2D > RigidBody2D
Physics2D > Collider2D
PlayerController -
Pickup:
Create C# Script: PickUp
GameData
Create C# Script: GameData
PlayerStats UI-Display:
Create c# Script: PlayerStats
Utility
Create C# Script: Utility
Spawner
Simple Spawner
ResultsPanel
StartButton
MiniGameManager
Floor
Ground