NPC Dialogue Script

Hello everybody. I got this script from the forums and I want it to be activated when I click on the character. But this activates when I push a key like s. Can somebody tell me how to change this.

var MyText     : String = String.Empty;
var ScreenArea : Rect;
//var TextArea : Rect;
//var MyFont     : GUIStyle;
//var DialogueBG : Texture2D;

private var DisplayThis : boolean = false;

function Update()
{
  if (Input.GetKeyDown(""))
     DisplayThis = !DisplayThis;
}

function OnGUI()
{
  if (DisplayThis)
     GUI.Box(ScreenArea, MyText);

/*
//alternatively...
  if (displayThis)
  {
     GUI.Label(ScreenArea, DialogueBG);
     GUI.Label(TextArea, MyText);
  }
*/
}

this script will activate if you push any key on keyboard it seem looking at the update(),

if (Input.GetKeyDown(""))
     DisplayThis = !DisplayThis;

so you need to change here, in a way when you click on your character you get the display.

now for the “OnCharacterClick” alike function it is up to you to use whatever you feel better suited for your needs , OnMouse fonction or a Raycast.

How would I do that. Where would I put it?

http://answers.unity3d.com/questions/3331/detecting-when-a-game-object-is-clicked-when-the-mouse-is-held-down-or-enters-o

Can somebody tell me where to put it using that script?

You put those methods on your script… Make sure the game object has a collider (it uses those to detect when the mouse is over it)

Where in the script? I don’t really know that much about scripting, so can you give me the script with that in it?

Here is a complete new script:

var MyText     : String = String.Empty;
var ScreenArea : Rect;
//var TextArea : Rect;
//var MyFont     : GUIStyle;
//var DialogueBG : Texture2D;

private var DisplayThis : boolean = false;

function Start()
{
  MyText = "Hello world! How are you doing?";
  ScreenArea = Rect (10, 10, 200, 100);
}

[COLOR="#006400"]//commented out[/COLOR]
function Update()
{
[COLOR="green"]  //if (Input.GetKeyDown(""))
  //   DisplayThis = !DisplayThis;[/COLOR]
}

[COLOR="green"]//Click and release the left button of a mouse[/COLOR]
function OnMouseUp() 
{
  DisplayThis = !DisplayThis;
}

function OnGUI()
{
  if (DisplayThis)
    GUI.Box(ScreenArea, MyText);
}

Any specifications as to how to activate the script?

Just attach this script to a character in your scene and click on the character to see the message in the box.