- Home /
How Do I Show and Hide GUI?
Hi guys. I am making an In-Game-Notepad so the player can write down notes, and I am trying to make it so that the "Player" can press "`n`" on his/her keyboard and either `Show` or Hide the Notepad.
this is the script I have so far...
var notePadText : String="NotePad...";
function OnGUI () {
notePadText = GUI.TextArea (Rect (5, 5, 200, 300), notePadText, 200);
}
ok so now I wan't to make it so the player presses a button (on there keyboard) and the notepad shows and hides but I cannot figure out how I can achieve that.
Thank you in advance! -Izzy
Answer by Piflik · Sep 06, 2012 at 08:55 PM
Wrap your complete GUI code in an if statement, where you check if a boolean variable is true and then use the key to toggle it.
var GUIEnabled : boolean = false;
var notePadText : String="NotePad...";
function Update () {
if(Input.GetButtonUp("n")) {
GUIEnabled = !GUIEnabled;
}
}
function OnGUI () {
if(GUIEnabled) {
notePadText = GUI.TextArea (Rect (5, 5, 200, 300), notePadText, 200);
}
}
Thank you! It works like a charm :D
I have made the script match my game and added in... Screen.lockCursor = false;
so that the players mouse show so he can select the notepad and when he hides the notepad... Screen.lockCursor = true;
$$anonymous$$eep up the great work!
HAHA im so stupid, it was so obvious. thank you piflik. although it was a bit off of what i was doing, i had to tweek it a little but you pointed out the obvious lol, thank you so much.
Answer by z25assassins · Apr 02, 2017 at 10:09 AM
try this video https://www.youtube.com/watch?v=q2HZNZvFFoo&t=3s
Your answer

Follow this Question
Related Questions
How to hide/show GUI Buttons through another GUI Button? 2 Answers
Hide / Disable GUI.Textfield in scene 2 Answers
Creating a Notepad 1 Answer
MonoDevelop defaulted, Unity opens scripts in Notepad? 1 Answer
In Game Notepad 2 Answers