Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 fullerfusion · Dec 10, 2018 at 03:06 AM · menubuttonspause gamenot respondingonkeydown

Pause Menu Buttons Not Working on First Attempt

Hi guys,

I need help with my Pause Menu I created. I made a script where if you hit the Escape button, the pause menu will appear and they'll be two buttons; home and resume. My mouse cursor hovers over the buttons and the two buttons should be highlighted and work, however it doesn't work properly.

What I mean by that is, the buttons do not become highlighted nor do they work. If I try to click on the buttons, my mouse will disappear and I can't do anything. I have to hit the Escape key to exit out of the Pause Menu and back into my scene. Then if I hit the Escape key again the Pause Menu will appear and now if I hover my mouse over the buttons they become highlighted and if I can click on any of them they start working. How do I fix this issue?

Here is my code:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityStandardAssets.Characters.FirstPerson;
 using UnityEngine.SceneManagement;
 
 public class PauseMenu : MonoBehaviour {
     public Transform PauseCanvas;
     public Transform Player;
 
     // Update is called once per frame
     void Update () {
         if (Input.GetKeyDown(KeyCode.Escape))
         {
             Resume();
         }
     }
     public void Resume()
     {
         if (PauseCanvas.gameObject.activeInHierarchy == false)
         {
             PauseCanvas.gameObject.SetActive(true);
             Time.timeScale = 0;
             Player.GetComponent<FirstPersonController>().enabled = false;
         }
         else
         {
             PauseCanvas.gameObject.SetActive(false);
             Time.timeScale = 1;
             Player.GetComponent<FirstPersonController>().enabled = true;
         }
     }
         public void Home()
         {
             SceneManager.LoadSceneAsync("Home");
         }
     }
Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Vega4Life · Dec 10, 2018 at 03:37 AM

Try to force it on...


         Cursor.visible = true;


Just put this underneath where you are turning the canvas on. If you still don't see it, then somehow your canvas my be having some z-fighting with the cursor.


Comment
Add comment · Show 3 · 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 fullerfusion · Dec 10, 2018 at 03:43 AM 0
Share

Hi @Vega4Life

I updated my question, because I wasn't clear. I see my mouse cursor and I can hover over my buttons. However, the buttons do not work. They do not become highlight nor do they work. If I try to click on the buttons, my mouse will disappear and I can't do anything. I have to hit the Escape key to exit out of the Pause $$anonymous$$enu and back into my scene. Then if I hit the Escape key again the Pause $$anonymous$$enu will appear and now if I hover my mouse over the buttons they become highlighted and if I can click on any of them they start working. How do I fix this issue?

avatar image darkStar27 fullerfusion · Dec 10, 2018 at 04:18 AM 0
Share

Ohk, What you can do is when you are in unity, play the game and select the pause menu game object while in play mode, check if every thing is enable by defalut.


You can also enable everything in a function and whenever you pause the game call the enabling function.

For Example: In

 public void Resume()
      {
          if (PauseCanvas.gameObject.activeInHierarchy == false)
          {
              EnableAllComponents();
              Time.timeScale = 0;
              Player.GetComponent<FirstPersonController>().enabled = false;
          }
      }
 void EnableAllComponents()
      {
          button1Object.SetActive(true);
          button2Object.SetActive(true);
          //.. And all the other pause menu components.
          PauseCanvas.gameObject.SetActive(true);
      }
 



avatar image fullerfusion darkStar27 · Dec 10, 2018 at 04:25 AM 0
Share

Hi @darkStar27

Question 1 In regards to using LoadSceneAsync, I believe I read somewhere that LoadSceneAsync would be helpful for loading scenes that have a lot of content in them. However, all my scenes I've created in Unity have never cause me any problems, or slowed down my computer. Do you suggest I change: Scene$$anonymous$$anager.LoadSceneAsync("Home");

to something else?

Question 2: Yes, this is a FPS game. I'm using the standard Unity's FPS Controller.

Okay, then that's understandable. I won't worry about that then.

avatar image
0

Answer by darkStar27 · Dec 10, 2018 at 04:09 AM

First of all tell me why are you using LoadSceneAsync instead of LoadScene or SetActiveScene.


Possible Reason

Coming to the problem at hand, if your game is a First Person Shooter, then when press Esc for the first time it is to show the mouse cursor (which is common with almost every FPS asset). So, you need to press Esc twice in order for it to work.

You can dig in the script files of you imported asset to set some other key to show mouse, or maybe add the pause menu code there to work at the same time.

.

Possible Solution

The easiest way would be to create a onscreen dedicated button for menu, or use buttons like Tab or Tilde as they aren't used in anything.


Another Reason

If its not a FPS game, try to map a different button instead of Esc, and check if the problem still occurs.

Comment
Add comment · 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

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

98 People are following this question.

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

Related Questions

Pause Menu open/close on key 1 Answer

iTween issue creating a gui. menu box 1 Answer

Button highlighted a pushable without touching it 0 Answers

Tutorials for 2D game GUI 2 Answers

Pause menu not working 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