Advancing Dialogue

Hello, I’ve been trying to work on this for hours now but I can’t seem to get it. I’m trying to make a conversation with let’s say two or three GUILayout.Label boxes and I want to make it so that when the player clicks the mouse button it goes to the next box, and etc. I kind of have an idea that you use

void Update()
{
    if(Input.GetMouseDown(0))
     {
      //something to skip to next box
      }
}

but I’m not sure what I put in to skip ahead. I can not figure out how to do this and if someone could poit me in the right direction that would be very much appreciated thank you. =P

How about something like this:

public string[] lines; // <-- Assign lines in inspector.
private int currentLine = 0;

void Update() {
    if (Input.GetMouseDown(0) && (currentLine < lines.Length)) {
        currentLine++;
    }
}

void OnGUI() {
    if (currentLine < lines.Length) {
        GUILayout.Label(lines[currentLine]);
    }
}
1 Like

I assigned the

public string[] lines;

but in the inspector I can’t change the number of it why is that?

Can you post a screenshot of the inspector? You should be able to expand the Lines foldout and enter a new value in the Count field.

I see it in the inspector it’s initial size is 0, but when I try to change this value it always reverts back to 0.

Woops got to click enter facepalming lol, thank you this way works. I was thinking of using iterators but I couldn’t figure it out thank you =P

Happy to help!