Im new to programming in general, and just recently started with GUI, so here is my problem:
var GUIon : boolean = false;
var xPos : int;
var yPos : int;
var Height : int;
var Width : int;
var bText : String = "Text in here!";
function Update() {
if ((Input.GetKeyDown(KeyCode.Escape)) GUIon == false) {
GUIon = true;
OnGUI();
}
if ((Input.GetKeyDown(KeyCode.Escape)) GUIon == true) {
GUIon = false;
}
}
function OnGUI() {
if (GUIon == true) {
if (GUI.Button (new Rect(xPos,yPos,Height,Width), bText)) {
print ("Button Pressed");
}
}
}
I get an error that sais “You can only GUI functions from inside OnGUI.”
how do i get rid of it?