• 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 /
This question was closed Mar 10, 2019 at 10:42 AM by Bunny83 for the following reason:

The question is answered, right answer was accepted

avatar image
Question by dreyescairo · Dec 21, 2014 at 10:03 AM · uibuttonpausing

Button is being triggered by spacebar after clicked once

I have a pause button in my space shooter game. When I pause, then un-pause, every time I use the space bar to shoot, it triggers the pause button. Is this because the pause button stays focused after being pressed once? Is it possible to un focus the button? I am using unity's 4.6 GUI system.

Pause button code:

     `public void pause(){
        if (Time.timeScale == 1) {
           Time.timeScale = 0;
           pauseText.enabled = true;
           mainMenuBT.gameObject.SetActive(true);

             } else {
           Time.timeScale = 1;
           pauseText.enabled = false;
           mainMenuBT.gameObject.SetActive(false);
             }
     }`

Any help in the right direction would be very much appreciated.

Comment
Bob-The-Zealot
dval
aboveyou00
pixel_fiend
IndieGeek
Puyol
correia55
ripperdave
Hanashimaru
Bunny83
badariqbaltihami
tezza2k1
tjbarrott
fax58

People who like this

14 Show 0
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

  • Sort: 
avatar image
Best Answer

Answer by Kyle_WG · Jun 09, 2015 at 04:21 PM

Sorry if irrelevant to you now but I thought I'd add for anyone else that comes across like me.

You can set the Navigation part of the UI.Button to None so it doesn't keep focus. It acts like a form so you can easily navigate from one UI element to another (like when you tab to other fields etc.) Mine was defaulted to automatic.

Unity version 5.0.0b18.

alt text


navi.png (15.5 kB)
Comment
ClintonFlowers
drHogan
dval
jektal0
Dave-Carlile
Marurban
gsorin
jinxed_byte
Vagonn
RishBee
Rodoleia
aboveyou00
ahmetabaci
mvandillen
pixel_fiend
And 78 more...

People who like this

93 Show 7 · 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 drHogan · Sep 15, 2015 at 09:05 AM 2
Share

I had the same problem and your solution was perfect. Cheers Kyle!

avatar image Kyle_WG drHogan · Sep 15, 2015 at 09:21 AM 0
Share

Excellent :)

avatar image jektal0 · Oct 05, 2015 at 06:42 PM 3
Share

Thanks! In my scenario, after clicking a button once the next click anywhere would trigger it again. Changing Navigation to None has fixed that and made it only fire when clicked!

avatar image Kyle_WG jektal0 · Oct 06, 2015 at 09:27 AM 0
Share

Great! Really surprised that it uses Automatic by default. Glad it helped.

avatar image brayhanreye · Feb 16, 2017 at 01:20 AM 2
Share

Thanks Kyle, that was simple and helpful.

avatar image mikewilliams76901 · May 16, 2017 at 03:57 PM 1
Share

You are my hero.

avatar image plszhao · Mar 10, 2019 at 09:58 AM 1
Share

Thank you very much!

avatar image

Answer by kevinspawner · Dec 22, 2014 at 10:39 AM

You need to create a bool and to trigger the pause on and off when required. Currently you are just scaling the time scale 1 and 0. You need to create a private or public bool and then enable and disable it to trigger the pause function. Hope it helps.

Comment

People who like this

0 Show 2 · 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 dreyescairo · Dec 24, 2014 at 07:11 AM 1
Share

Thanks for the reply. I actually just got it to work. Turns out that space bar was an alternate positive in the Input Manager for the button. I had to go to Edit > Project Settings > Input. Then under Submit, I reassigned the Alt Positive Button to something other than the space bar. I can now Pause then un-pause and shoot with the space bar without accidentally triggering the pause button every time.

avatar image kevinspawner · Mar 12, 2015 at 04:12 AM 0
Share

Cool. Glad you got it working.

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta on June 13. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

9 People are following this question.

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

Related Questions

Launching an animation with new GUI in Unity 4.6 1 Answer

(4.6 UI) Button is highlighted permanently 3 Answers

How to create a button for every supported resolution? 1 Answer

How do I reset GUI Button to normal state texture(Android)? 0 Answers

[Solved] (4.6 UI) Button is highlighted without mouse hovering 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