One Text box after another problem

I have already made another topic about this but I wanted to add on some more information about what I’ve done.

Basically I’m wanting to create an NPC conversation with one text box appearing after another with text in when the user presses a button which currently is “Z”. I’ve done all the scripting for the text and made it so it prints one letter at a time also but I just can’t think of a way to have one text box after another and I think that’s mainly due to the way I’ve scripting the text manager.

This is the code within my text manager:

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class TextManager : MonoBehaviour {
	public GameObject textbubble;
	public Text textbox;

	public GameObject NPC;

	public bool isTyping;
	public bool finishedText;

	void Start () {		
		NPC = GameObject.Find ("NPC");
	}
		
	//To Input Text and Animation for NPC
	public void InputText(string text, Sprite sprite, float typeSpeed){
		
		StartCoroutine (TypeScroll (text, typeSpeed));
		NPC.GetComponent<SpriteRenderer> ().sprite = sprite;
	}

	public IEnumerator TypeScroll(string lineOfText, float typeSpeed){
		int letter = 0;
		textbox.text = "";
		isTyping = true;
		finishedText = false;

		while(isTyping && letter < lineOfText.Length) {
			textbox.text += lineOfText [letter];
			letter++;
			yield return new WaitForSeconds (typeSpeed);

			if (letter == lineOfText.Length) {
				isTyping = false;
				finishedText = true;

			} else {
				if (Input.GetKey (KeyCode.Z)) {
					textbox.text = lineOfText;
					isTyping = false;
					finishedText = true;
				}
			}
		}
	}
}

All it does is basically take in a string, a sprite of the NPC and then the speed of which it will print out the letter and then runs it all in a IEnumerator.
This is how i call the function:

textManager.InputText ("Calling the function", sprites [0], 0.1f);	

I did this so i could easily change the sprite of the NPC for depending on what he’s saying or even slow or speed up the type speed depending on what he’s saying.

Someone on the last topic i made about this mentioned using a array but the problem with that, that i didn’t mention in the last post is I can’t easily change the sprite or type speed then as it would keep looping through the same line of code while adding one to the index of the array to print out each string in that array one after the other.

So basically I’m wondering if anyone has I way i can print one message after another if the user presses a button that works with my function?

Thanks

One way to do it is to make a little class that holds the three things you want to pass to your InputText function: Text, Sprite, Speed. Then you can make an array/list of this class to hold all the different lines you want to display, and loop through that.

Example of Class to hold data

public class DialogueLine
{
	public string text;
	public Sprite sprite;
	public float typeSpeed;

	public DialogueLine(string _text, Sprite _sprite, float _speed)
	{
		text = _text;
		sprite = _sprite;
		typeSpeed = _speed;
	}
}

Example of how to create a Dialogue Line and add it to a list

public List<DialogueLine> lines;
lines.Add(new DialogueLine("Text", OldManSprite, 5f));

Example of how to use it in your script

public List<DialogueLine> lines;
    int currentLine = 0;
    ...
    	void PlayNextLine()
    	{
    		InputText(lines[currentLine].text, lines[currentLine].sprite, lines[currentLine].typespeed);
    		currentLine ++;
    	}

void Update()
{
    if (Input.GetKeyDown (KeyCode.Z)) {
	    PlayNextLine();
    }
}