So I made simple and really easy to use dialoque script that allows you to make simple and small conversations with npc or yourself. There is also audio which is added to list so you can play audio same time with correct text on screen.
using UnityEngine; using System.Collections; using System.Collections.Generic; using System.Xml; using System.Text; using System.IO; public class Dialog : MonoBehaviour { //distance between npc and player public float distance; public Transform player; public bool activez; //number that decides which text is shown and which is not. public int count; //dictionary where we store our text Dictionary<int, string> test = new Dictionary<int, string>(); //List for Audio files. Drag and drop files to here in inspector public List<AudioClip> audios = new List<AudioClip>(); // Use this for initialization void Start() { //all text is stored in dictionary and accessible with numbers test.Add(0, "Text 1"); test.Add(1, "Text 2"); test.Add(2, "Text 3"); test.Add(3, "Text 4"); test.Add(4, "Text 5"); test.Add(5, "Text 6"); test.Add(6, "Text 7"); test.Add(7, "Text 8"); test.Add(8, "Text 9"); test.Add(9, "Text 10"); test.Add(10, "Text 11"); test.Add(11, "Text 12"); test.Add(12, "Text 13"); test.Add(13, "Text 14"); test.Add(14, "Text 15"); test.Add(15, "Text 16"); test.Add(16, "Text 17"); test.Add(17, "Text 18"); test.Add(18, "Text 19"); } // Update is called once per frame void Update() { //if player is close enought npc we "activate" script distance = (transform.position - player.position).magnitude; if (distance < 5) { activez = true; } else { activez = false; } } void OnGUI() { //if script is "actived" if(activez == true) { // if count is 0 which is the start, do gui button that changes count to 1 if pressed to start "conversation" if(count == 0) { if(GUI.Button(new Rect(Screen.width/2,Screen.height/2,250,50),"Hey there do you understand me?")) { //Play audio file "element" 0 in list audio.clip = audios[0]; audio.Play(); //make count to 1 count = 1; } } //if count = 1 we make 3 more gui buttons wich set count to 2,3,4 if(count == 1) { GUI.Label(new Rect(10,Screen.height/2,500,100),test[4]); if(GUI.Button(new Rect(Screen.width/2,Screen.height/2-100,250,50),test[5])) { //Play anotehr audio file from audio list audio.clip = audios[1]; audio.Play(); //make count to 2 count = 2; } if(GUI.Button(new Rect(Screen.width/2,Screen.height/2-200,500,50),test[6])) { audio.clip = audios[2]; audio.Play(); count = 3; } if(GUI.Button(new Rect(Screen.width/2,Screen.height/2-300,250,50),test[7])) { audio.clip = audios[3]; audio.Play(); count = 4; } } //checks if count is 2 ,3 ,4 and gives us text and back button, //wich takes count back to earlier number, so you can choose again if(count == 2) { GUI.Label(new Rect(10,Screen.height/2,500,100),test[8]); if(GUI.Button(new Rect(Screen.width/2,Screen.height/2-300,250,50),test[12])) { count = 1; } } if(count == 3) { GUI.Label(new Rect(10,Screen.height/2,500,100),test[9]); if(GUI.Button(new Rect(Screen.width/2,Screen.height/2-300,250,50),test[12])) { count = 1; } } if(count == 4) { GUI.Label(new Rect(10,Screen.height/2,500,100),test[10]); //if player presses this button we move conversation to count 5 if(GUI.Button(new Rect(Screen.width/2,Screen.height/2-300,250,50),test[13])) { count = 5; } if(GUI.Button(new Rect(Screen.width/2,Screen.height/2-200,250,50),test[12])) { count = 1; } } } //if count = 5 button will spawn if player clicks it, //it will start coroutine lol if(count == 5) { if(GUI.Button(new Rect(Screen.width/2,Screen.height/2-200,250,50),test[14])) { count = 6; StartCoroutine("lol"); } } if(count == 7) { GUI.Label(new Rect(Screen.width/2,Screen.height/2-200,250,50),test[15]); } if(count == 8) { GUI.Label(new Rect(10,Screen.height/2,500,100),test[16]); } if(count == 9) { GUI.Label(new Rect(Screen.width/2,Screen.height/2-200,250,50),test[17]); } if(count == 10) { GUI.Label(new Rect(Screen.height/2 +100,Screen.height/2-50,500,100),test[18]); } } //waits several seconds and then shows different texts and plays audios IEnumerator lol() { audio.clip = audios[4]; audio.Play(); count = 7; yield return new WaitForSeconds(7); audio.clip = audios[5]; audio.Play(); count = 8; yield return new WaitForSeconds(5); audio.clip = audios[6]; audio.Play(); count = 9; yield return new WaitForSeconds(7); audio.clip = audios[7]; audio.Play(); count = 10; yield return new WaitForSeconds(2); count = 11; } }