- Home /
Question by
davidflynn2 · Nov 23, 2012 at 03:43 AM ·
gui
Make GUI.TextArea show up only when Left Ctrl pressed
I would like to make it so my GUI.TextArea only shows when the left ctrl key is pressed.
This is the code I have It just never causes it to show up.
function OnGUI() {
if (Input.GetKeyDown ("left ctrl"))
{
GUI.TextArea( textrect, formText );
}
}
Comment
Best Answer
Answer by Democre · Nov 23, 2012 at 05:01 AM
You should not use Input inside the OnGUI function. Also GetKeyDown, only returns true when the key is first pressed. GetKey returns true as long as the key is pressed. Instead set a flag and use that inside OnGUI.
var showingTextArea = false;
function Update ()
{
showingTextArea = Input.GetKey (KeyCode.LeftControl);
}
function OnGUI ()
{
if(showingTextArea) {
GUI.TextArea( textrect, formText );
}
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
GuiTexture Width Change 1 Answer
Preventing Rapid Fire 2 Answers
Noobish Question Pertaining to JS Movement 2 Answers
Leave space between GUILayout.Label 1 Answer