API ››
Parent Previous Next


public class MiniGame_Controller : MonoBehaviour

This Class implements the flow and monetization logic for all MiniGames

It provides some free rounds and then allow paying for extra chances and purchasing currency if there is not enough.


MiniGame _Game

Game this controllers manages

bool _StartGameOnEnable

If true, the game will be initialized when this object is enabled

float _TimeBeforeStartRound

This delay can be used to start the round after some effects/sounds are finished

Events to hide/show labels and update texts

UnityEvent _OnStartPlaying

Show/Hide objects for the initial state, execute the entrance effect and call OnReadyForNextRound right after it finishes

UnityEvent _OnRoundStarted

UnityEvent _OnGameOver

Free Rounds

int _InitialFreeRounds

How many rounds are allowed without having to pay for them

string _FreeRoundsLabelFormat

Format of the label showing how many free chances are available. (e.g. Select {0} boxes)

{0} is replaced by the number of free rounds

UnityEventString _OnUpdateFreeRounds

Shows the Free Round button and updates the label's text following the _FreeRoundsLabelFormat

Purchasable Rounds

string _CostLabelFormat

Format of the label showing the cost of selecting a new slot (e.g. {0} coins to open a box)

{0} is replaced with the cost. And it follows the equation:

cost = InitialCost + ExtraCost * NumPurchases

int _InitialRoundCost

(Default: 10) How much cost the first round after the free ones are over

int _ExtraCostPerRound

(Default: 5) How much to increase the cost of the following rounds

UnityEventString _OnUpdateRoundCost

Hides the Free Round button, shows the Buy Chance


UnityEvent _OnShouldBuyCurrency

Open the popup to buy currency and when finished calls ValidateRound again or DenyRound

UnityEventCurrency _OnConsumeCurrency

Consume currency and returns the result using the supplied callback

Internal Variables

int mNumFreeRounds

Remaining free tries

int mNumPayedRounds

Number of times the players has bought a spin

bool mIsPlaying

it's true whenever the game is initialized and it's possible to play another round

int CurrencyAmount

Fake Currency (this is used only for the demo, when used in a game, the _OnConsumeCurrency event should be redirect to the game's resource to decrease the currency and call OnConsumeCurrencyResult with true/false depending on whatever there was enough currency available


Public Methods

void StartGame()

Initializes the game and starts the first round

void ResetGame()

Restarts the game from the beginning

void OnReadyForNextRound()

Execute _OnGameOver, _OnUpdateFreeRounds or _OnUpdateRoundCost based on game state

void ValidateRound()

Checks if there are free rounds or enough currency to buy a new round.

If so, it calls AllowRound, otherwise it shows the BuyCurrency popup or denies the round

void OnConsumeCurrencyResult(bool Success)

This should be called after the ValidateRound tried to buy currency,

If there are not enough available the BuyCurrency popup is executed

void AllowRound()

After the round is validated, this function continues the game flow to play another round (PrizeWheel: spins the wheel, etc)

void DenyRound()

The round validation failed, so this function stops the current play attempt

Created with the Personal Edition of HelpNDoc: Easily create CHM Help documents