Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

How do I back up though an existing dialog between NPC's?

Hello, I am new here so if this is out of place, I am sorry. I have went though the How to make a Dialogue System in Unity. Every thing works perfectly and I would just like to add a way for the player to back up through the conversation.

Here is my dialog manager:

public class DialogueManager : MonoBehaviour

{

   public Dialogue[] conversations;

private Queue<string> sentences;

   private int index = 0;

   public Text nameText;

   public Text dialogueText;

   public AudioSource TypeSound;


   //public Animator animator;


   // Start is called before the first frame update

   void Start()

   {

       DialogueTrigger dialogueTrigger = FindObjectOfType<DialogueTrigger>();

       conversations = dialogueTrigger.conversations;

       sentences = new Queue<string>();

       Time.timeScale = 0;

       TypeSound = GetComponent<AudioSource>();

   }


   public void StartDialogue(Dialogue conversation)

   {

       //animator.SetBool("isOpen", true);

       nameText.text = conversation.name;


       sentences.Clear();


       foreach (string sentence in conversations[index].sentences)

       {

           sentences.Enqueue(sentence);

       }


       DisplayNextSentence();

   }


   public void DisplayNextSentence()

   {

       if (sentences.Count == 0)

       {

           EndDialogue();

           return;

       }


       string sentence = sentences.Dequeue();


       StopAllCoroutines();

       StartCoroutine(TypeSentence(sentence));

   }


   IEnumerator TypeSentence(string sentence)

   {

       TypeSound.Play();

       dialogueText.text = "";

       foreach (char letter in sentence.ToCharArray())

       {

           dialogueText.text += letter;

           yield return null;

       }

       TypeSound.Stop();

   }


   public void EndDialogue()

   {

       index++;

       if (index < conversations.Length)

       {

           StartDialogue(conversations[index]);

           return;

       }

       else

       {

           Debug.Log("End of dialogue.");

           //animator.SetBool("isOpen", false);

       }

       Time.timeScale = 1;

   }


   public void setIndex(int index)

   {

       this.index = index;

   }

   public void DisplayPreviousSentence()

   {


       Debug.Log("back it up");

   }

Sign In or Register to comment.