MiniGameManager

Code updated 9/17/2020

To complete Project 1: Create The following GameObjects:

MiniGameManager: Empty GameObject

ResultsPanel Page:

  • ResultsPanel: UI-Panel with CanvasGroup Component

  • ResultsText: UI-Text - child of ResultsPanel

StartButton Page:

  • StartButton: UI-Button

MiniGameManager.cs

This script will be on emptyGameObject: MiniGameManager You'll need to populate public fields in the inspector once you have created the other required gameObjects. See Images below:

Put Script on an empty gameObject in the Scene.

Overview - MiniGameManager.cs:

The MiniGameManager Class manages logic for:

  • Start Button to Start Gameplay

    • Function ReStartGame( ) is executed when the StartButton is clicked

      • Resets GameData

      • Hides the Results Panel:

      • Sets the curGameState to MiniGameState.active

      • Hide the StartButton so it's inactive (hidden)

      • Set the Spawner activeSpawning = true

      • Execute Spawner StartSpawning( ) method.

  • Polling - Code Executed in Update( ): - Checked Every Frame

    • Checks to determine what the current value of curGameState

    • if curGameState ==MiniGameState.active

      • Check that Health is still greater than 0

      • If Health is Greater than 0

        • Check Score, if Score > WinScore

          • Set MiniGameState.Win

          • Set win text for ResultsText.text

          • Call GameOver( )

      • Else if Health is Less than or equal to 0

        • Set MiniGameState.Lose

          • Set lose text for ResultsText.text

          • Call GameOver( )

  • GameOver( ) Method

    • Show ResultsPanel ( Use Utility to set CanvasGroup values)

    • Show StartButton - setActive is true, makes visible

    • Stop Spawner by activeSpawning = false

    • Spawner: StopAllSpawning( ) Also destroys all spawned objects

Code MiniGameState, MiniGameManager

See Version2 below for Included Spawner Code

Version 2 - With Spawner Code Added

The code below is a simplified version, either version should work, select the one you prefer

Last updated

Was this helpful?