Minigame Procedure - HealthStart-Monstralia/Monstralia GitHub Wiki

Components

A minigame is composed of the following:

  1. A specific manager script that handles the game's flow and process
  2. A UI Canvas
  3. Stickers
  4. Minigame Asset Data
  5. Back Button
  6. Usage of GameManager (for levelup and countdown calling)
  7. Usage of SoundManager (for queueing voice overs and playing sound effects)
  8. A tutorial in the beginning of the game, teaching the player how to play
  9. A review version of the game

Process

  1. Create a scene in the _Scenes folder and under the appropriate part of the island (e.g. Brainbow belongs in BrainstormLagoon). Make sure the name of the Scene matches exactly what is defined under the DataType script.
  2. Create a Canvas with the following settings:
  • Canvas: Render Mode: Screen Space - Camera
  • Canvas: Render Camera: Main Camera
  • Canvas: Sorting Layer: UI
  • Canvas Scaler: UI Scale Mode: Scale with Screen Size
  • Canvas Scaler: Reference Resolution: X 768 Y 1024
  • Canvas Scaler: Screen Match Mode: Match Width or Height
  • Cancas Scaler: Match: 0
  1. Add a back button using the prefab under the Canvas you created.
  2. Inside that scene create a GameObject with a manager script.
  3. In the manager script, inherit from AbstractGameManager and implement any abstract functions from it.
// Example class
public class BrainbowGameManager : AbstractGameManager<BrainbowGameManager> {
    // Some code here

    public override void PregameSetup () {
        // Code here
    }

    // Code here
}
  1. If you're going to use the Awake function make sure to put the 'new' keyword beside it and use base.Awake(); as this is crucial for maintaining the singleton property.
new void Awake() {
  base.Awake();
  // Code here
}
  1. Develop the game with your manager script handling the game flow.
  2. Call Game Manager functions to level up, give a sticker, and unlock new levels. Use other managers as a reference.
  3. In Scripts>Data>Minigames, create a Minigame Asset by right-clicking Create>Data>Minigame Data and assign the variables if applicable. Game Manager will load all assets inside the minigames folder automatically.
  4. When creating any scripts specific to the minigame, please prefix it with the name. For example, Brainbow scripts are prefixed with Brainbow.

Useful functions to use

Calling singleton classes

To access a reference to a class that inherits from Singleton<> such as Game Manager, you do not need a direct reference. You can access it through its static variable. This includes your Minigame Manager since it inherits from AbstractGameManager<> which inherits from Singleton<>.

GameManager.Instance.WhatEverFunctionYouWantToCall();
SoundManager.Instance.SoundFunction();

Countdown inside your Minigame Manager

StartCountdown(FunctionToCall); // This will conduct a countdown from GameManager and then call the function you gave it.

// Example function, this is called at the end of the countdown
void FunctionToCall () {
    // Start game
}

Updating the score gauge using the current score and maximum score

    void UpdateScoreGauge () {
        if (scoreGauge.gameObject.activeSelf)
            scoreGauge.SetProgressTransition ((float)currentScore / scoreGoal);
    }

Gameover

GameOver (DataType.GameEnd) is a function that is defined in AbstractGameManager designed to handle showing the endgame screen.

    // Player reached goal
    if (score >= scoreGoal) {

        // If level one, give player a sticker and complete the level, 
        // otherwise complete the level normally.
        if (difficultyLevel == 1) {
            GameOver (DataType.GameEnd.EarnedSticker);
        } else {
            GameOver (DataType.GameEnd.CompletedLevel);
        }
    } 
        
    // Player did not reach goal, show game over
    else {
        GameOver (DataType.GameEnd.FailedLevel);
    }

Creating the player monster

monsterCreator is a CreateMonster variable on a GameObject. It returns the Monster script on the instantiated monster.

GameObject monsterObject = monsterCreator.SpawnPlayerMonster ().gameObject;

Play SFX, Voiceover, or Music from SoundManager

clip is an AudioClip variable.

SoundManager.GetInstance().PlayVoiceOverClip(clip);     // Play voiceover.
SoundManager.GetInstance().AddToVOQueue(clip);          // Add voiceover to queue and play it, SoundManager will play next VO once current VO is done.
SoundManager.GetInstance().ChangeBackgroundMusic(clip); // Change background music
SoundManager.GetInstance().ChangeAmbientSound(clip);    // Change ambient sound
SoundManager.GetInstance().PlaySFXClip(clip);           // Play the SFX. SoundManager will create an audiosource and play your SFX. Maximum 8 sources can be played all at once.

Handling the clock

public float timeLimit;
public TimerClock timerClock;     // Assign in inspector or use the following code
private TimerClock timerClock;
timerClock = TimerClock.Instance; // Use in Start() or PregameSetup()

Functions you can use that are mostly self-explanatory.

timerClock.SetTimeLimit(timeLimit);
timerClock.StartTimer();
timerClock.StopTimer();
timerClock.TimeRemaining();
timerClock.AddTime();
timerClock.allowTimeNotification = true;  // A time out notification pops up informing the user.

Written by Colby Tang