- Home /
In Game Notepad
Hi Guys, I am thinking on adding an In-Game-Notepad. I have written a basic starter script
var stringToEdit : String = "Notes:";
function OnGUI () {
if (Input.GetKeyDown ("n"))
stringToEdit = GUI.TextArea (Rect (400, 400, 200, 100), stringToEdit, 200);
}
I wan't the player to be able to press "n" and a window opens up where he can write down stuff e.g Memos,reminders etc.
But I can't get the window to show up?
Thank you in advance! -Izzy
Answer by Screenhog · Sep 05, 2012 at 05:52 PM
If it's a notepad, that would mean that you want a player to be able to actually save information on it, right? Should the notepad info get saved when you leave a game and come back?
I think it would be ok not to save for now, and then when I wan't it to save in the future I can change the script
Answer by wherr · Aug 01, 2014 at 09:32 PM
When using OnGUI(), the gui has to be rendered every frame. So, if you have it render when you press a button, it will only render for a very slight amount of time. I think something like this will help:
var stringToEdit : String = "Notes:";
var menuOpen : boolean = false;
function OnGUI () {
if (Input.GetKeyDown ("n")) {
menuOpen =! menuOpen;
}
if (menuOpen) {
stringToEdit = GUI.TextArea (Rect (400, 400, 200, 100), stringToEdit, 200);
}
}
Sorry if my syntax is incorrect, I am used to C#.
When using OnGUI(), the gui has to be rendered every frame
OnGUI is actually called multiple times per frame. Hence why it sucks hard on the performance.