Right, so...when I started looking for learning sources and videos regarding how to build a multiple choice dialogue system, as yep that's what I was aiming for, my excitement quickly turned into confusion! My goodness, there are so many different ways of building a dialogue system from using nodes in Unity, to scripting and creating scriptable assets or objects.
After reading and watching a variety of sources I decided to go with a system that is flexible enough to be used in a variety of future games. It has an event system that uses scriptable objects, which are quite useful. I watched Semag Games eight video tutorial How to Create a Flexible Dialogue System . The tutorial shows how build it for a 2D game. However with a few minor adjustments I was able to implement it into my 2.5D game. Have a look, its a pretty cool system and very flexible to be used in a variety of games.
After watching the series once I decided this was a tutorial I wanted to go ahead with as it is very flexible and I will find good use for it in my future games.
Now, If you are like me then you will agree when I say that there is nothing worse than watching a tutorial watching some person speak a lot of code, not explaining what it is actually means, to end up with scripts full of code that goes over your head by just looking at it. This wont happen with this series, I promise. The author explains the process in depth from how to create the UI elements, how to use each video's end result, and lastly the code. Also, you can not just go and download the scripts from a website so you will have to invest time in writing it. Therefore learning more about it as you go.
Right, enough talking about the existence of good and bad coding tutorials and lets see what I ended up spending time on in the past 3 days. Yup, it took me three days to finish it. I guess that's what happens when you have four kids (well five if I count hubby and yes he'd agree with my statement).
First day
On my first day I managed to set up the UI canvas, write a script using IEnumerator that makes the text appear with a typewriter effect which looks pretty funky and a speed parameter was added to control the speed of the appearing text..
Using scriptable objects I made a dialogue object that allows for multiple dialogues to be created using a bunch of instances of the scriptable object rather than having to hard code each one. I made two dialogues this way where the player clicks the left mouse button after the first dialogue finishes to go to the next dialogue.
Second day
The second day was definitely a bit more challenging than the previous day but I managed to understand it after re-watching video four and five.
I managed to create a response system with scriptable objects that allow you to create responses to a dialogue in unity, linking them together. Instead of adding a "Button" component, it was explained how to code the response button by using an OnClicked and OnClickedResponse method. This was very interested.
I did at a certain point ran into a problem that when I chose a response, it would not actually allow me to click it at all. After some searching on the net (as I looked over my scripts until I was sure it was not them at fault) I noticed that I had the EventSystem missing in the hierarchy. Silly me!
Lastly, a method was added that allows the appearing text to make a pause when certain punctuation appears. For example after a comma it waits for a float of 0.3 and after a full stop 0.6. This was achieved by using "struct" and "HasSet" punctuation method where you can choose which punctuation you wish to use and "wait" time for each.
Third and final day
This day was quite exciting as events were added depending on the chosen response. For example if the character comes back to the same NPC after agreeing he understood the previous dialogue and leaving, then the NPC would ask him if he came back for more information. Or another example would be after a chosen response the camera zooms out. There are many events you can set up using this system which is pretty cool and useful.
Another feature added was a "skip" option where the player can skip the dialogue to the point where a response is needed by clicking the left mouse button.
I asked Scott to have a run though the level, showing the dialogues popping up with the responses and skip function after the player clicks the left mouse button. When the adventurer comes back after leaving, the King asks to make haste and save his son.
The Lost Prince : Level 1 - Off to meet the King