Now, I know a thread has been brought up about this:
http://forum.unity3d.com/viewtopic.php?t=17516&highlight=gui+button+keypress
But that’s not what I’m looking for. What I want it to do, is if I press the “JUMP” button (Space in my case), click the button. I don’t want my player to use the mouse at all to continue my conversations (much like in a Mario game where you hit the A button to continue dialog, which is also the jump button). I’ve got everything working so far in my test, but I just want the button to react to a keypress, not a mouse click:
private var stayInTrigger = 0.0;
private var talkMode = false;
static var talking = false;
function OnTriggerEnter()
{
//Starts a timer.
stayInTrigger = Time.time;
}
function OnTriggerStay ()
{
//If I'm in the trigger long enough, allow me to talk instead of jump.
if (Time.time > stayInTrigger + 1.00)
{
talking = true;
}
//If I press my "accept button" AKA the JUMP button, open the dialog.
//Also make sure talking is on, and talkmode isn't activated.
if (Input.GetButton ("Jump") talkMode == false talking == true)
{
//Turn on Talk Mode to start the dialog
talkMode = true;
//Turn off movement
ThirdPSWalker.isControllable = false;
}
}
//If I leave my trigger, be sure to allow jumping again.
function OnTriggerExit()
{
talking = false;
}
function OnGUI()
//Turning off talkMode allows the dialog to disappear.
{if(talkMode == true)
{
if(GUI.Button(Rect(0,0,500,500), "Lookie lookie! Click me to end this dialog!"))
{
//A quick little shortcut so that I don't have to type the same things over and over again.
EndDialog();
}
}
}
function ContinueDialog()
{
//Not finished yet
}
function EndDialog()
{
//Give the player control again.
ThirdPSWalker.isControllable = true;
//Close the "dialog box".
talkMode = false;
}
Again, I want to click my Jump button (The accept button) To use my dialog boxes, not my mouse.
In order to do this by keypress, you need to set your script up to perform functions in the update function. It’s actually quite touchy and you need a delay for nearly everything O.o It works though.