In the last tutorial, we created a two-level conversation tree, but it's a little basic. We want options to appear organically as we choose other options, and we also want some options to give different responses when chosen more than once. We'll add both of these features now.
First of all, we don't want the player to declare their love of hippos until they've learnt something about them, so let's disable this option by default. Select our Hippos base conv prefab. In its Inspector, select I sure do love me a hippo from the list of options, and uncheck Is enabled?. This will keep it hidden when the Conversation begins.
We’ll want to enable this option once the player has asked a question - that is, chosen either of the two question options we created in the Hippos questions Conversation object.
Return to the Talk about hippos Cutscene, and find the branch of Actions related to the Where to hippos live? dialogue option:
Create a Dialogue: Toggle option Action beneath it, and set it to the following. When run, it will enable the I sure do love me a hippo option in the first Conversation:
Re-wire the branch so that this Action is run following the two speech Actions, and we return to the conversation Action afterwards:
We’ll also want the disabled option to appear if we ask the What’s their latin name? question, so re-wire that branch to end on that Action as well:
Now, once the player learns a fact about hippos, they’ll be able to tell the NPC that they love them!
However, if people start repeating themselves in real life, people take notice. So let's give the NPC something different to say each time the player declares their love of hippos.
Find the branch of Actions related to the I sure do love me a hippo option:
Create a Variable: Run sequence Action in an empty space, and set it up as the following:
This Action will cycle through it’s three output sockets, running a different one each time the Action is triggered. We can use this to make our NPC give different responses each time the player chooses the I sure do love me a hippo option.
If we wanted to record the number of times this Action has been run in save-game files, we can declare a variable and connect it to this Action.
Drag this new Action, and the two speech Actions that make up the option’s branch, into a clear space, and re-wire them as follows:
This means that the NPC will only reply “Me too!” for the first time that the player chooses this option. Create a new Dialogue: Play speech Action for the two other output sockets on the Variable: Run sequence Action as follows:
As with the “Me too!” response, re-wire these two new Actions so that they return to the Dialogue: Start conversation Action that starts this Cutscene.
Re-run the scene and test out the conversation. You'll have to ask a question before you can tell the NPC that you love hippos - and when you do repeatedly, you'll get a different response each time.