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:
- 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 
 
- 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 
 
- GameData - Singleton gameObject to store score, health, etc. 
ToDo:  Add the following GameObjects and Scripts
- User Interface - PlayerStats Display - Display changing score, health to give player feedback about game-play actions. 
- Utility: C# Static Class with Static Methods, ex: modify CanvasGroup alpha 
- Spawner - Script on Empty GameObject. Script will randomly instantiate PickUp prefabs. 
- 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 - MiniGameState enums - manage GameState: idle, active, win, lose 
- StartButton visibility controlled by MiniGameManager logic - StartButton executes Listener Method: RestartGame( ) to set MiniGameState to MiniGameState.active 
 
- ResultsPanel - visibility and text - controlled by MiniGameManager logic - 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
Project 1 GameObjects, Scripts
Steps to Create and Configure Player GameObjects:
- Player gameObject - Add Physics2D > RigidBody2D 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 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 - 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
- Pickup: 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 
- 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 
 
- GameData: Create C# Script: GameData - Add GameData as a Script Component to new Empty GameObject named: GameManager 
 
New GameObjects, Scripts
- PlayerStats UI-Display: Create c# Script: PlayerStats - Add Script to a UI-Panel that has 2 children: UI-Text ScoreText, UI-Text HealthText. 
- Utility (Static Class) Create C# Script: Utility - 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 );
- Spawner Create C# Script: Simple Spawner Add Script to an Empty GameObject: Spawner, - In inspector panel, add PickUp prefabs from assets folder to the Spawner script component for GoodPrefab, BadPrefab attributes. 
 
- ResultsPanel - becomes visible to show final MiniGameState: win / lose, otherwise CanvasGroup alpha = 0, to hide panel 
- StartButton - functions as event-listener - executes ReStartGame( 
- MiniGameManager Create C# Script: MiniGameManager, Add Script to Empty GameObject: MiniGameManager - In inspector panel, add ResultsPanel, StartButton, Spawner as attributes to the MiniGameManager script component 
 
Last updated
Was this helpful?
