- Home /
 
               Question by 
               Robbit · Dec 17, 2013 at 08:43 PM · 
                javascriptonguionmousedownargumentexception  
              
 
              OnMouseDown and GUI function
I'm trying to enable a level change when selecting a game object. I'm having a rough time and keep on getting "You can only call GUI functions from within ONGUI". Any help would be greatly appreciated. Here's my script so far:
 #pragma strict
 
 function Start () {
 
 }
 
 function Update () {
     if (Input.GetKey("mouse 0")){
         buttonPressed = true;
     }    
 }
 
 var buttonPressed = false;
 
 function OnGUI () {
     if (buttonPressed == true){
     // Make a background box
     GUI.Box (Rect (10,10,100,90), "Navigation");
 
     // Make the first button. If it is pressed, Application.Loadlevel (1) will be executed
     if (GUI.Button (Rect (20,40,80,20), "1st Floor")) {
         Application.LoadLevel ("first_floor");
     }
 }
 }
               Comment
              
 
               
              I don't see anything in this script that will generate that error. Not sure what you want here, but if you are trying to click on a specific object and this script is on the specific object, then use On$$anonymous$$ouseDown():
 function On$$anonymous$$ouseDown() {
     buttonPressed = true;
 }
Your answer
 
 
             Follow this Question
Related Questions
Using Time with OnGUI Help 2 Answers
I need some help on inventory. 0 Answers
Two IF statements in a OnGUI function problem 1 Answer
help with script 3 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                