We can now make the GameController responsible for choosing and switching which games to play. We'll randomly pick a new ball game after each throw.
The GameController will be populated with the list of ball games, subscribe to their events, and then decide to activate or deactivate ones. Modify the script as follows:
File: GameController.cs
Replace ballGame with a list of ballGames, the current game index, and add a Boolean to ensure we initialize only once:
public BallGame[] BallGames; private int currentGameIndex; private bool isInitialized;
Then, add this code to Start():
for (int i = 0; i < BallGames.Length; i++) { BallGames[i].OnGoalWon.AddListener(WonGoal); BallGames[i].OnGoalLost.AddListener(LostGoal); ...