MiniGameManager
Code updated 2/17/2020
MiniGame Manager
This script will be on emptyGameObject: MiniGameManager You'll need to populate public fields in the inspector. See Images below:
Create The following GameObjects:
ResultsPanel: UI-Panel with CanvasGroup Component ResultsText: UI-Text - child of ResultsPanel StartButton: UI-Button MiniGameManager: Empty GameObject

Put Script on an empty gameObject in the Scene.

Overview - MiniGameManager.cs:
This 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 GameState to MiniGameState.active
Sets the StartButton so it's inactive (hidden)
Starts the Spawner
Set the Spawner's activeSpawning = true
Calls Spawner's StartSpawning( ) method.
Polling - Code Executed in Update: - Checked Every Frame
Checks to determine what the current MiniGameState is
if MiniGameState.active
Check that Health is still greater than 0
If Health is Greater than 0
Check Score, if Score > WinScore
Set MiniGameState.Win
Call GameOver( )
Else if Health is Less than 0
Set MiniGameState.Lose
Call GameOver( )
GameOver( ) Method
Set Result Text to Win or Lose message
Make ResultsPanel visible ( Use Utility to set CanvasGroup values)
StartButton - setActive is true, makes visible
Stop Spawner by activeSpawning = false
Destroy any remaining spawned objects
DisplayResult - This method is called when the Game
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?