Hi, I’m trying to make a dialogue box similar to the quest boxes in WoW, and I’ve got it working almost perfectly, but not quite.
Two issues:
1. The scroll bar doesn’t work. This is the first time I’ve ever tried to make anything with a scroll bar, and I’m a little lost. Basically I just need to know how to attach the scroll bar to the text area so it can control it.
2. The player can highlight the text, which I don’t want, but I couldn’t figure out how to get the text to display except by using a TextArea, which inherently allows the user to highlight the text.
My code:
var highlighted = false; // Used to determine whether or not NPC is highlighted
var talk = false; // Used to determine whether or not NPC is talking
var title : String; // Title of the textbox for the NPC dialogue
var dialogue : String; // The dialogue of the NPC (i.e. what the NPC says)
var asset : TextAsset; // Points to the text file that contains the NPC dialogue
// Changes the color of the material while the mouse is over the mesh
function OnMouseOver ()
{
renderer.material.color = Color(1.5, 1.5, 1.5);
highlighted = true;
}
function OnMouseExit ()
{
renderer.material.color = Color(1, 1, 1);
highlighted = false;
}
// Detect left mouse click and print it in the debug log.
function OnGUI()
{
var click : Event = Event.current;
if(click.button == 0 click.isMouse)
{
if (highlighted == true)
{
//Debug.Log("Left Click");
talk = true;
}
}
if (talk == true)
{ //(horizontal position, vertical position, horizontal size, vertical size)
GUI.Box(Rect(50,50,325,400),title);
if (GUI.Button(Rect(350,53,22,15),"x"))
{
//Debug.Log("Closed the dialogue box.");
talk = false;
}
//(h-position, v-position, h-size, v-size)
GUI.TextArea(Rect(60,75,290,345),dialogue);
dialogue = asset.text;
var vSbarValue : float;
//(h-position, v-position, h-size, v-size)
vSbarValue = GUI.VerticalScrollbar(Rect (354, 76, 100, 343), vSbarValue, 1.0, 10.0, 0.0);
if (GUI.Button(Rect(315,425,55,20),"Accept"))
{
//Debug.Log("Accepted the quest.");
talk = false;
}
if (GUI.Button(Rect(255,425,57,20),"Decline"))
{
//Debug.Log("Declined the quest.");
talk = false;
}
}
}