A relatively complex solution would be to store all the page data in arrays, as well as the buttons in each page and their functions. An important variable to understand is pageChanges. I use that to show which page has what kind of buttons, and which page they lead to.
Each entry should have this format: “currentPage”-“pageToGoTo” (so, 1-3 would mean that we should create a button in page 1 that takes us to page 3. For its name, we are going to use the buttonNames array; for instance, if “1-3” is in position X of the pageChanges array, we are going to use buttonNames to name the button that is in page 1 and takes you to page 3.
We can also detect whether the entry is named “Exit” and leave the dialogue with it.) The arrays buttonNamesForPage and pageChangesForPage should have a length equal to the maximum amount of dialogue available in a page.
They are ultimately unnecessary, but they will simplify things.
var pageChanges:String[];
var pageChangesForPage:int[];
var buttonNames:String[];
var buttonNamesForPage:String[];
var pageToShow:int=0;
var pageTitles:String[];
var pageTexts:String[];
var pageImages:Texture2D[];
function OnGUI(){
//Draw a gui box with the title being pageTitles[pageToShow]
//draw the pageImages[pageToShow] text.
//draw the page text the same way.
//Now we are going to parse the pageChanges data to see how many buttons the page will have
var thisPagePointer:int=0;
for(var i:int=0;i<pageChanges.length;i++){
var textPointer:String[]=pageChanges*.Split("-"[0]);*
if(int.Parse(textPointer[0])==pageToShow){
pageChangesForPage[thisPagePointer]=textPointer[1];
buttonNamesForPage[thisPagePointer]=buttonNames*;*
thisPagePointer++;
}
}
//Now we have assigned all the data we need to our arrays, time to make buttons
GUILayout.BeginVertical(); //you need a GUILayout, it’s up to you to customise the coordinates of the GUI.BeginArea that should go in front of it.
for(var j:int=0;j<thisPagePointer;j++){
if(GUILayout.Button(buttonNamesForPage[j])){
if(pageChangesForPage[j]==“Exit”)
QuitDialogue();
else
pageToShow=int.Parse(pageChangesForPage);
}
}
}
function QuitDialogue(){
//do things to stop the dialogue and start playing
}
It’s a somewhat complex solution but it should get the job done. I’ll give you setup examples in a bit.
Examples: Let’s assume that in the first dialogue box you want to give the player two choices, a “Hi” choice that takes the user to another page and an “Exit” choice. You also want the second page to be the last and only contain an “exit” choice.
This is how the arrays should be set up:
pageChanges: [“0-1”,“0-Exit”,“1-Exit”] //Exclude the brackets in all of these
pageChangesForPage: Set length to 2
buttonNames: [“Hi”,“Leave”,“Leave”]
buttonNamesForPage: Set length to 2
pageTitles: [“You see a person down the street”,“You greet the person”]
pageTexts: [“What do you say to the person?”,“The person greets you as well and continues down the road”]
pageImages: [image of you , image of stranger]
The buttons will be created in the order that the page changers are found in the pageChanges array, so if the array looks like […,“1-3”,“0-4”,“0-2”,…] , the button that takes you to page 4 will be shown first in page 0.