Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Phil25 · Jun 12, 2012 at 12:51 AM · touchmenuissuepause

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

Comment
Add comment · Show 13
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image The1nk · Jun 12, 2012 at 01:23 AM 0
Share

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)

avatar image Berenger · Jun 12, 2012 at 01:42 AM 0
Share

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

avatar image The1nk · Jun 12, 2012 at 01:58 AM 0
Share

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

avatar image Berenger · Jun 12, 2012 at 03:30 AM 0
Share

Then disappear I shall.

avatar image The1nk · Jun 12, 2012 at 03:51 AM 0
Share

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

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1

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.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Phil25 · Jun 12, 2012 at 05:47 PM 0
Share

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.

avatar image Berenger · Jun 12, 2012 at 07:17 PM 0
Share

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; } } }

avatar image Phil25 · Jun 12, 2012 at 09:06 PM 0
Share

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

avatar image joseaguirre · Feb 23, 2014 at 04:12 PM 0
Share

how do you hide the gui box and just show a sprite as your resume button?

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges