- Home /
(JS) Touch pause menu issue
Hello everyone! I've made a script, witch checks if the touchpad is touched and stops time, setting the variable paused = true, hiding the HUD(including the touchpad) and displaying the GUI.Button. The problem is: after the touchpad(named lePauseButton) is touched IT DOESN'T DISPLAY THE BUTTON. Here's the script:
 var lePauseButton : Joystick;
     lePauseButton.active = true;
 var paused : boolean = false;
 
 var resumeButton : Texture2D;
 
 var hud : GameObject;
     hud.active = true;
 
 function Update () {    
     if (lePauseButton.IsFingerDown() && !paused){
         print("Paused");
         Time.timeScale = 0.0;
         paused = true;
         
         hud.active = false;
         lePauseButton.active = false;
     }
 }    //it's like the script from now on doesn't even exist.
 
 function OnGUI () {
     if(paused){
         if(GUI.Button (Rect (Screen.width/2 - 100, Screen.height/2 - 200, 200, 100), resumeButton)){
             print ("Unpaused");
             Time.timeScale = 1.0;
             paused = false;
         
             lePauseButton.active = true;
             hud.active = true;
         }
     }
 }
That's pretty much it, I've spent over 5 hours on studying the sctipt, raped the google for answer but i couldn't find a thing. Help will be much appreciated. Take Care!
if you put a print("test"); or something similar as the first command in the function OnGUI () { block .. does it print?
Actually .. I wonder if it's something as crazy as you setting the Time.timeScale = 0.0; causing both the Update() and OnGUI() functions to never be called again .. because the time is stopped? .. Enter .. the Twilight Zone.. .. Crazy idea. xD (edit: combined two comments into one)
It will work, but it's going to slow down your computer. print is hell of a function.
@Berenger - the print() function I asked for was just for debugging to see if the OnGUI() function was even being called. :P If it is, then move the print() down into the if() block nested within, and of course .. continue as necessary. That's how I'd debug this, anyway. :\
@Berenger - Strange that the image you posted has been making huge appearances all over 4chan .. and you post it .. Coincidence or conspiracy!? I think NOT!
Answer by Berenger · Jun 12, 2012 at 04:03 PM
The reasons for OnGUI not be called are : 1) the function's name is incorrect (not your case). 2) The gameObject is inactive. 3) The component is disabled. I doubt that your problems is in those three cases.
FIRST IDEA : A timeScale null won't stop the GUI call, that would be unfortunate for a pause menu. So the problem comes from the boolean "paused". I don't think you ever get the print "Paused", which means the input is incorrect. I don't code on mobiles so I can't help, but I'm sure there is a lot of informations about it.
SECOND IDEA : The pause works, the GUI button is drawn, however the texture is incorrect. Missing, too big, doesn't fit, you name it. Try with a string first. The button style should be visible however, so this seems unlikely.
Thank you for the answer but everything you described above won't help. As you doubted, those 3 reasons aren't the problem. I get the print("pause") and I checked if the GUI button is correctly positioned and scaled. Unfortunately the problem still remains.
I tried that code (replaced the touch by getkey) and it does work. The error must come from elsewhere.
var paused : boolean = false; var resumeButton : Texture2D;
function Update () { 
 if ( Input.Get$$anonymous$$eyUp($$anonymous$$eyCode.Space) && !paused) { print("Paused"); Time.timeScale = 0.0; paused = true; } }
function OnGUI () { if(paused) { if(GUI.Button (Rect (Screen.width/2 - 100, Screen.height/2 - 200, 200, 100), resumeButton)) { print ("Unpaused"); Time.timeScale = 1.0; paused = false; } } }
Thank you Berenger, I see what the problem is.. Damn.. when i was setting pauseButton.active=false when paused=true, I realized that the resumeButton GUI that I wanted to show up then was attached as a child to pauseButton, and it was disappearing with it. Thank all of you for your help, I wouldn't think of it...
how do you hide the gui box and just show a sprite as your resume button?
Your answer
 
 
             Follow this Question
Related Questions
Restart Problem 1 Answer
Unity Pause Menu Still Has Camera Movement! 1 Answer
Animating a button press from maya file problems 0 Answers
Pause menu scripting help? 1 Answer
Hold the esc button for a pause menu 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                