I am making this fairly simple dialogue system, simple for now at least, and i want it so that regardless of the length of what needs to be said, the choice buttons are positioned correctly. By this i mean when i have the NPC say just, “Yes” The button is placed accordingly, while if i have the NPC go into a rant that requires scrolling i want the Buttons to be at the bottom of the rant. I have it set up so that the whole dialogue takes place in a window. Inside the window is a ScrollView, and inside the scrollview is the GUI Label i am using to display the text, and a GUI Button that closes the conversation. Here is the code i am working with:
private var windowRect : Rect = Rect (Screen.width/2 -400, Screen.height/2+200, 250, 300);
var scrollViewVector : Vector2 = Vector2.zero;
static var display : boolean = false;
function OnGUI () {
if(display) {
windowRect = GUI.Window (2, windowRect, WindowFunction, "NPC Name");
}
}
function WindowFunction (windowID : int) {
// Begin the ScrollView
scrollViewVector = GUI.BeginScrollView (Rect (25, 43, 220,200), scrollViewVector, Rect (0, 0,0, 600));
GUI.Label (Rect (25,0,170,550), "Dialogue");
if(GUI.Button (Rect (35,96,80,30),"Close")) {
display = false;
}
// End the ScrollView
GUI.EndScrollView();
GUI.DragWindow (Rect (0,0,10000,100));
}
It’s pretty simple, when the player hits the ‘Interact’ button (e), a script shoots a ray forward to see if there is a object tagged ‘NPC’. If it does, i plan on using scripts to go into the NPC that was hit, get a script titled something like ‘npcDialogue’ and that will contain the information that will send both the Dialogue, and the Name to this script to render it on screen.
For now, i have it set up so when i talk to NPC it simply tells this script to render the Window, inside is just some test dialogue. Now, what i want is the button to close it (which in the future may be more then one button that will lead to branching conversations) to be just below the text regardless of the length. This is my first time at truly using Unity’s GUI features so i do not know the best way to approach this. Sorry for it being so long winded!
Short Version: Have the button be just below the text contained inside of the GUI Label, regardless of what is inside the label.