x


(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!

more ▼

asked Jun 12 '12 at 12:51 AM

Phil25 gravatar image

Phil25
0 1 2

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)

Jun 12 '12 at 01:23 AM The1nk

It will work, but it's going to slow down your computer. print is hell of a function.

Jun 12 '12 at 01:42 AM Berenger

@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. :\

Jun 12 '12 at 01:58 AM The1nk
Jun 12 '12 at 03:30 AM Berenger

@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!

Jun 12 '12 at 03:51 AM The1nk
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Jun 12 '12 at 04:03 PM

Berenger gravatar image

Berenger
11.2k 12 19 54

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.

Jun 12 '12 at 05:47 PM Phil25

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.GetKeyUp(KeyCode.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;
		}
	}
}
Jun 12 '12 at 07:17 PM Berenger

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...

Jun 12 '12 at 09:06 PM Phil25
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x699
x606
x402
x268
x127

asked: Jun 12 '12 at 12:51 AM

Seen: 442 times

Last Updated: Jun 12 '12 at 09:06 PM