Having a GUI Display elements in an Array [SOLVED :3]

Alrighty, I’ve actually got a toughie X3 What I have is a simple script that I can slap on anything I want to talk to (of course I’m missing one element, but I’m working on the mechanic first). Slap it onto a sign, give it three elements of text, then it will display each one until I’ve went through all of the elements.

var guiSkin: GUISkin;
//var nativeVerticalResolution = 1200.0;

private var stayInTrigger = 0.0;
private var talkMode = false;
static var talking = false;

private var dialogcontinue = false;
private var endTalking =  0.0;
private var talkDelay = 0.0;

private var WindowWidth = Screen.width * .90;
private var WindowHeight = Screen.height * .20;

var WhatImSayingElements : String[];
//private var WhatImSaying = "Lookie lookie! Press Jump to end this dialog!";

function FixedUpdate()
{

//My way of getting GUI to react to a on a button click, not a mouse click

//Make sure I'm talking/reading
if (talkMode == true)
{
//When I hit the jump button...
if(Input.GetButton ("Jump"))
{
//Give some time to delay, otherwise I'll zoom through text
	if (Time.time > talkDelay + .5)
	{
//If I have more dialog use my now unfinished "ContinueDialog()" function
	if (dialogcontinue == true)
	ContinueDialog();
	else
//Nothing else? Finish talking/reading
	EndDialog();
	}
}

}

}

function OnTriggerEnter()
{
stayInTrigger = Time.time;
}

function OnTriggerStay ()
{
//Make sure I'm in the trigger long enough to turn off my Jumping ability.
if (Time.time > stayInTrigger + 1.00)
	{
		talking = true;
//This would also put a little "Talk (A)" picture above the object that you're going to talk to, but I don't have that finished.
//I'm going to do two functions for that, ShowPopupPicture() and ClosePopupPicture(), to show and erase the picture.
	}

//It seems like a lot, but it basically says:
//If I'm not already in talkmode, and I'm allowed to talk. If I hit the jump button (accept button) Show the dialog.
//The endTalking is a delay timer to prevent the accept button from continually executing.

if (Input.GetButton ("Jump")  talkMode == false  talking == true  Time.time > endTalking + .5)
	{

//talkMode turns on my Talking GUI
		talkMode = true;

//Turns off my controls so I don't run away while I'm talking/reading.
		ThirdPSWalker.isControllable = false;

//talkDelay will also be used to prevent a player from zooming through the text.
		talkDelay = Time.time;
	}

}

function OnTriggerExit()
{
//Give the Jump button control back to the controller so I can jump again.
talking = false;
}

function OnGUI()

//talkMode turns my GUI on and off.
{if(talkMode == true)
{
	GUI.skin = guiSkin;
	
	GUI.Label (Rect ((Screen.width/2 - WindowWidth/2),(Screen.height - WindowHeight),WindowWidth,WindowHeight), WhatImSayingElements + "", "box");

//I will also have an accept button picture at the bottom right of the box in order to make it feel like a Nintendo game X3
}
}

//Unfinished, it's supposed to bring up the next element in the array.
function ContinueDialog()
{

}

//Close the dialog and give control back to the player. Also start the delay timer to prevent the player from opening the dialog again.
function EndDialog()
{
		ThirdPSWalker.isControllable = true;
		talkMode = false;
		endTalking = Time.time;
}

I can get my Dialog box to display one variable of text (I had “private var WhatImSaying” instead), but I want it to display 1 element at a time until I’m done with elements.

What I want it to do, is to detect the number of elements I have in my Array. If the I’m at the max # of elements in that array, set off the “EndDialog” function, but if I’m not done, with my array, use my “ContinueDialog” which will then display the next element in the array… Ah, I hope I’m not confusing anyone reading this ^^;;

Well, still thinking about this one, what I was thinking was something like this: (Note: not real code!)

var TalkIndex = 0;

(Update)
if (TalkIndex = WhatImSayingElements.Length - 1)
ContinueDialog = false;
//This would prompt the close dialog Continue Dialog would then automatically be true... Either that or I switch ContinueDialog with EndDialog and just flip the states around O.o

(OnGUI)
Label(Rect(position,sizing,WhatImSayingElements[TalkIndex].ToString +"", "box");

//This -should- react to what my Talk Index is, and give me the right Text Element first.

(ContinueDialog)
TalkIndex += 1;
//Add 1 to the talk Index, so that it brings up the next element...

(EndDialog)
TalkIndex = 0;
//I would then add this so that it resets my elements, and plays the correct ones in sequence again.

Does this seem doable? It’s kind of what I think would work… but I’m not sure. I just want my “Dialog Box” to ‘play’ a certain sequence of text.

“if (TalkIndex = WhatImSayingElements.Length - 1)” Should bring up the last element, (lets say there’s three) so if my index is 2, it should tell my code not to continue the dialog before it has a chance to add it again…

Got it… My dialog box was showing some weird things for a second there, but I got it :3

var guiSkin: GUISkin;
//var nativeVerticalResolution = 1200.0;

private var stayInTrigger = 0.0;
private var talkMode = false;
static var talking = false;

private var dialogcontinue = true;
private var endTalking =  0.0;
private var talkDelay = 0.0;

private var WindowWidth = Screen.width * .90;
private var WindowHeight = Screen.height * .20;

var WhatImSayingElements : String[];
private var TalkIndex = 0;

//This one is needed because you cannot extract directly from arrays
private var WhatImSaying : String;

function Start()
{
	if (WhatImSayingElements.length == 0)
	Debug.Log ("Your Object doesn't have anything to say! Give it something or it won't work!");
//Unity will automatically tell you that your array is out of range, this will clarify the error and tell you, you didn't add anything for your thing to say.
}

function FixedUpdate()
{

if (TalkIndex == WhatImSayingElements.length - 1){
dialogcontinue = false;}

//Put the correct phrase in my dialog box
WhatImSaying = WhatImSayingElements[TalkIndex];

if (talkMode == true)
{
if(Input.GetButton ("Jump"))
{
	if (Time.time > talkDelay + .5)
	{
	if (dialogcontinue == true)
	ContinueDialog();
	else
	EndDialog();
	}
}

}

}

function OnTriggerEnter()
{
stayInTrigger = Time.time;
}

function OnTriggerStay ()
{

if (Time.time > stayInTrigger + 1.00)
	{
		talking = true;
                //I still don't have a little pop-up thing here... That's all I need now :3
	}
	
if (Input.GetButton ("Jump")  talkMode == false  talking == true  Time.time > endTalking + .5)
	{
		talkMode = true;
		ThirdPSWalker.isControllable = false;
		talkDelay = Time.time;
	}

}

function OnTriggerExit()
{
talking = false;
}

function OnGUI()
{if(talkMode == true)
{
	GUI.skin = guiSkin;
	
	GUI.Label (Rect ((Screen.width/2 - WindowWidth/2),(Screen.height - WindowHeight),WindowWidth,WindowHeight), WhatImSaying + "", "box");
	//Yes, that's seriously all you need :3
}
}

function ContinueDialog()
{
TalkIndex +=1;
talkDelay = Time.time;
//Set off the Talk delay so you don't speed through everything, and add one to your index

//This was just telling me if I was hitting the right numbers.
Debug.Log("TalkIndex is now " + TalkIndex + ", while The element length is " + (WhatImSayingElements.length - 1));
}

function EndDialog()
{
		ThirdPSWalker.isControllable = true;
		TalkIndex = 0;
		talkMode = false;
		dialogcontinue = true;
		endTalking = Time.time;

//Reset EVERYTHING and give control back to my player
}

This code is pretty much done :3 I just have to slap it on stuff and then add elements to it :3 Easy freaking talking/reading system XD