Let’s make a Dialogue System that you can easily tweak to suit your game!
● Listen to the Podcast:
● Download the Project:
● Download the Font:
● Singleton:
♥ Support Brackeys on Patreon:
····················································································
♥ Donate:
♥ Subscribe:
● Website:
● Facebook:
● Twitter:
····················································································
Edited by the lovely Sofibab.
····················································································
► All content by Brackeys is 100% free. I believe that education should be available for everyone. Any support is truly appreciated so I can keep on making the content free of charge.
····················································································
♪ “Funin and Sunin” Kevin MacLeod (incompetech.com)
Licensed under Creative Commons: By Attribution 3.0 License
♪ Baby Plays Electro Games
Nguồn: https://sam-pointer.com/
Xem thêm bài viết khác: https://sam-pointer.com/game/
If your code does not work: check if you misspelled
if you did everything right and you can't press button: add event system(dialogue box>>right click>>UI>>event system
If you are using text mesh pro and does not work: delete and use text and do as same as in the video
If my comment helped you let me know and like so other people can see too
Thank u for the tutorial. Sir, or someone, please help me with how to do a conversation with many NPCs with 1 Talk button?
For anyone getting null reference error in sentences.Clear(); because you are calling automatically from a void start(), u could make a Invoke("mymethod", 0.5); where mymethod would be the startDialogue(dialog); and "0.5" seconds to before trigger it. it works for me because i want the dialog start almost before loading the scene.
Does anyone know how to start the dialogue not from the button but from the Script?
if anyone is having an issue where the console keeps displaying "object reference not set to an instance of an object" and points you to the dialogue manager script, my fix was changing sentences.Clear(); to sentences = new Queue<string>(); and the issue was gone, idk why it was making a fuss but it did for me, also make sure not to set a scope on the trigger procedure because it gave me the same error 😀
Great breakdown, thank you!!
I've rewatch this to many times.
I made a custom typeSentence function that fixes the issue where the word starts on one line and jumps to the next because it overflows.
IEnumerator typeSentence(string sentence)
{
float timePerLetter = 0.01f;
dialogueText.text = "";
int maxCharPerLine = 75;
int maxChar = maxCharPerLine;
int currentChar = 0;
string[] words = sentence.Split(' ');
for (int i = 0; i < words.Length; i++)
{
if(currentChar + words[i].Length > maxChar)
{
dialogueText.text += "n";
maxChar = dialogueText.text.Length + maxCharPerLine;
}
//able to fit in line
for (int j = 0; j < words[i].Length; j++)
{
//every letter in word adds to text and waits
dialogueText.text += words[i].ToCharArray().GetValue(j);
yield return new WaitForSecondsRealtime(timePerLetter);
}
dialogueText.text += ' ';
currentChar = dialogueText.text.Length;
}
//dialogueText.text = sentence;
}
If you want the text to appear faster/slower you can do something like this (it could be crap but it works)
IEnumerator TypeSentence (string sentence)
{
DialogueText.text = "";
foreach (char letter in sentence.ToCharArray())
{
DialogueText.text += letter;
for (int i = 0; i < 10; i++)
// Change "10" to change the speed of the writing
{
yield return null;
}
}
}
Thanks!
Did anyone else think, "Damn it Visual Studio, why do you always open on the monitor that playing video?", when Brackeys opened up Visual Studio?
I just came here because I was curious, but now I'm terrified of what programmers are capable of… Respect for you all who can do such things as programming 👍👍
Why in foreach fragment (below) there is foreach(string sentence in dialogue.sentences) not foreach(string sentence in sentences). I don't understand what dialogue.sentence here is for.
I am asking about this fragment of code:
public void StartDialogue(Dialogue dialogue)
{
Debug.Log("Starting conversation with " + dialogue.name);
sentences.Clear();
foreach (string sentence in dialogue.sentences)
{
sentences.Enqueue(sentence);
}
DisplayNextSentence();
}
At 4:39 but…cant add anything to Test Button. Keeps saying the script class cannot be found. But i did everything exactly as shown…even double checked i did all the steps in exact order… 😓😓 help! I know nothing of coding so mybe i missed something. Ran into this issue with another tutorial. Using 2019 version of unity so not sure it all translates to an updated version…
how to make it so it do it automatically?, like i dont want to press it. just by itself
hello, I want to learn how to bound the input field to only the 0-1 number is allowed to input for the in unity. and how to generate the dialog box if the t is wrong.
This is better than other paid ones. (Unity got still the best Tuts but they created Unity and they are a big company)
can someone help me how to add some pic on the npc?
well damn, that was simpler than I thought it would be
how to make same button to start and continue as well
Como adicionar esse dialogo em um npc para ativar na tecla "SPACE"?
How to add this dialog in an npc to activate on the "SPACE" key?
Can anyone help me, I've been trying to figure out how to make the autocomplete work in VS
dude no joke u saved me a lot of trouble thank u so much for letting us download the project
Thank you for this nice tutorial!
I paused the game during the dialogue. For those of you who want to do the same, set the Update Mode of the Animator to "Unscaled Time", then instead of "yield return null" use "yield return new WaitForSecondsRealtime(typingSpeed)" where typingSpeed is a float variable storing the time delay between the appearance of the characters. Finally, all that is left to do is to set "Time.timeScale = 0" in the StartDialogue method and to set "Time.timeScale = 1" in the EndDialogue method.
How do I close the dialogue box after the last line of text? Any suggestions, instead of just a debug log inside of the EndDialog method in the dialogManager script.
This is an excellent application of OOP and really making use of the more advanced features of C#.
Dude, how do you save this thing? Can you make a tutorial for saving dialogue?