Dialogue System
Last updated
Last updated
Two scripts will be needed. The one that manages the UI. The other, triggers that contain their own unique content.
Reference Video: https://youtu.be/PswC-HlKZqA?si=sjOrSJlxms0ay4zm
If you click on a GameObject in the scene view, then hover you mouse over the scene window and then hit "F" it will focus the view on that object. This is useful because canvases are huge in the Unity UI.
Then remember to save the file. Take the original file name and add "_TMP" at the end to keep track of what is a TMP font.
This is only added once for the entire game. Add these basic functions. Remember, these need to be public so that the trigger can communicate with it.
Add the packages at the top, before the Monobehaviour line.
Setting up variables in the script. We need to hook up the UI components to the script.
Note the updated hierarchy in the scene list.
Add the DiaManager.cs script to the UI parent gameobject. Then hook up the things.
We also need to know when the UI is open, so that we can close it. We'll just be checking if the dialogue box is open with:
Now to start with the first function. This is the Hide function.
This has options for with or without the actor. For some reason, I can't pass the sprite as a variable.
This will be added to all Interactible GameObjects. It will open the functions in the DiaManager and pass information to it.
When the trigger is hit by the interact raycast, we need the conversation to begin. We'll add in a public function.
It needs to send the variables to the DiaManager. These are all the Variables:
For some reason, I can't share the "Sprite" image into the UI Image although the videos show this is possible. I give up.
Simply add a second Hide() function in the DiaManager.cs. Then, drag it onto the OnSubmit event in the Player Input from the Inspector. Why do we do this? Well, if you're using the space bar to begin the conversation, this without the callbackContext fires the regular Hide() function immediately, so the conversation just blips on the screen. This makes sure that the second function has to wait until the next key press.