How would one go about scripting “cut scenes” that aren’t really animated cut scenes? Let’s say I wanted a person to click on a button, something to happen (a tutorial) and in that tutorial have a bunch of things moving on their own?
Example:
This arrow goes here to show this person where to click for this.
After clicking that, the game “Plays itself” to show the player how the game mechanics work
Then the player must repeat that to show they understand
etc, etc.
Would I just have to write one very specific script and write out each event and trigger them when I need to? Or is there an easier way than writing a long script?
Coroutines are the best answer for this, probably. You can do any arbitrary scripting action, then wait for any arbitrary condition, then do more things. It’d take the general form of something like this:
void Start() {
StartCoroutine(Tutorial());
}
public IEnumerator Tutorial() {
tutorialText.text = "Welcome to the tutorial! Press X";
while (!Input.GetKeyDown("x")) yield return null;
tutorialText.text = "Good job! Now move to position (0, 10, 0)";
while (Vector3.Distance(playerObject, new Vector3(0f,10f,0f)) > 0.5f) yield return null;
tutorialText.text = "And so on";
}
We use PlayMaker. It’s a finite state machine that’s consistently a top 3 seller in the Unity Assets store.
I would recommend using finite state machines over co-routines. Co-routines are harder to debug as you can have a hundred of them running at once. A finite state machine makes sure only one thing is happening at a time.