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 /
This question was closed Jul 03, 2015 at 06:10 AM by daviddickball for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by daviddickball · Jul 02, 2015 at 09:30 PM · buttoncanvasenabled

Buttons on disabled canvas still catching keypresses

I have a weird bug in my code where pressing space seems to be triggering a button on a canvas that's recently been disabled.

So at the end of my game I show a canvas with 2 buttons, "back to menu" or "continue playing". alt text "Keep playing" calls a function which disables the canvas. I use this code below:

 goalCompleteCanvas.GetComponent(Canvas).enabled = false;

But then if I press space, it calls the function of the button that was clicked again, even though the canvas was disabled and the buttons are hidden. If I press a cursor key and use space I can actually select the other button too.

How can I hide this canvas and stop any of the buttons from being triggered?

Comment
Add comment · Show 2
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 felixpk · Jul 02, 2015 at 09:33 PM 0
Share
 goalCompleteCanvas.gameObject.SetActive(false);

should do the thing?

avatar image felixpk · Jul 02, 2015 at 09:35 PM 0
Share

If you don't want to disable the whole GameObject you can attach a Canvas Group Component and then set the alpha to zero and uncheck Interactable and blocks Raycast, the con of this is that it is still rendered even though the alpha is set to zero.

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by daviddickball · Jul 02, 2015 at 09:35 PM

Oh wait, I could just disable the gameObject instead of the component.

No idea why I didn't think of that.

I'm an idiot.

Comment
Add comment · Show 1 · 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 felixpk · Jul 02, 2015 at 09:50 PM 0
Share

yeah like I said ;)

Follow this Question

Answers Answers and Comments

22 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

Related Questions

Canvas button with 2 functions onClick must be pressed twice for 2nd function? Will not disappear? 1 Answer

Parent with animator component prevents child buttons to get click 0 Answers

Animator Not Playing on Button Click 0 Answers

Whole Screen Touchable 0 Answers

UI button does not press if colliding with other UI object 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