It is common in games of any complexity to point things out for the player to do, in sequence, to get the hang of it when it’s his or her first time playing.
For example in an RTS, you might start the first mission with one unit, and you display an arrow pointing to it with a message telling them to click on it. Then when they do, tell them to move it to a certain area, then to attack a given enemy, then move somewhere else, then make another unit appear and have them click a button to show its abilities, then to click on a certain one, etc.
I’m trying to conceptualize what would be the most elegant, and flexible, way of implementing such an event-based system once you already have the engine built. Having a tutorial that waits for desired actions at given times, while still running the whole engine, is sort-of like having dozens of “winning conditions”, only one of which is valid at a time.
The only practical way I can think of is to have a global int for the current tutorial step, and then to fill each possible event involved in the tutorial with conditions, such as:
if(tutorialStep==3 || tutorialStep==16 || tutorialStep==27)
//Do the button's actual logic here
As you can imagine, it’d become a bit bloated to fill the code for every button, action or keystroke that’s involved in the tutorial with conditions like this, especially if it’s comprehensive and involves at some point each of the dozens of actions you can perform in the game. This would for example require running code inside a unit movement function to check whether we’re in a tutorial and, if so, whether we’re selecting the object we’re supposed to for the current step, and if so, whether it’s going to the desired location etc.
It would be preferable to have everything in a separate Tutorial class which when activated could somehow be watching all events such as button clicks, locations of given objects, keystrokes or any other action that you want to register to it at some point or another.
Has anyone implemented such a system in Unity, which also has the flexibility to add new steps for future buttons or actions in one place?