---
description: Overview of Project1 GameObjects and C# Scripts
---

# Project1 GameObjects

## 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( )**&#x20;
   * **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&#x20;
   * **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

**Sorting Layers** is the preferred method for ordering sprite layering for rendering. [Unity Tutorial Video on SortingLayers](https://unity3d.com/learn/tutorials/topics/2d-game-creation/sorting-layers)

## Project 1 GameObjects, Scripts

### **Steps to Create and Configure Player GameObjects:**

1. **Player gameObject**
   * Create [**Animation using Animator Controlle**r](../animation/animation-steps)
   * Add [**Physics2D > RigidBody2D**](../project-1-simple-game/player_gameobject) Component - this is required for objects that will have **movement**, physics forces should be used to give movement to gameObjects.
     * **Set Constraints**: Freeze Rotation Z-axis
   * Add [**Physics2D > Collider2D**](../project-1-simple-game/player_gameobject) 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:** [**PlayerController** -](../project-1-simple-game/playercontroller-v4) Versions 1-4 - includes logic for movement, collision, update score, health
   * 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

1. [**Pickup:**](../project-1-simple-game/pickup_items) **Prefabs** Create Several 2D Sprite Game Objects: (objects for the player to interact with - we'll call these **PickUp** objects )
   * 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
   * [Create C# Script:  **PickUp** ](../project-1-simple-game/pickup_items)
     * 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
2. [**Floor**](../../project-1-simple-game/player-gameobject-jump#floor) - Create an empty GameObject, attach a BoxCollider2D, edit the collider so it is a wide rectangle, move toward the bottom of the screen.
   1. Create, Set custom **physics Layer**:  [**Ground**](../../project-1-simple-game/player-gameobject-jump#custom-layer-ground) (for Player jump behavior)
3. [**GameData**](../project-1-simple-game/gamedata)**:** [Create C# Script: **GameData** ](https://github.com/kdoore/cs2335_v2/tree/e629ce99d3c4e27e0dc9a8b416a206a1d7051d22/gamedata-simple.md)
   * Add GameData as a Script Component to new Empty GameObject named: **GameManager**

### **New GameObjects, Scripts**

1. [**PlayerStats UI-Display:**](playerstatsdisplay-version1) [ Create c# Script: **PlayerStats** ](playerstatsdisplay-version1) - Add Script to a UI-Panel that has 2 children: **UI-Text ScoreText, UI-Text HealthText.**
2. [**Utility**](utility-class) **(Static Class)** [Create C# Script: Utility](utility-class) - **Static class, Static methods:**&#x54;his 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 );`**
3. [**Spawner**](simple-spawner) Create C# Script: [Simple Spawner](simple-spawner) Add Script to an Empty GameObject: **Spawner,**&#x20;
   1. In **inspector panel,** add **PickUp prefabs from assets** folder to the **Spawne**r script component for **GoodPrefab, BadPrefab** attributes.
4. [**ResultsPanel**](minigamemanager/resultspanel) **-** becomes visible to show final MiniGameState: win / lose, otherwise CanvasGroup alpha = 0, to hide panel
5. [**StartButton**](minigamemanager/startbutton) **- functions as event-listener - executes ReStartGame(**
6. [**MiniGameManager**](minigamemanager) Create C# Script: MiniGameManager, Add Script to Empty GameObject: **MiniGameManager**
   1. In **inspector panel, add ResultsPanel, StartButton, Spawner** as attributes to the MiniGameManager script component&#x20;

###

##
