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 /
This question was closed Aug 11, 2017 at 04:27 PM by Igor_Vasiak for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Igor_Vasiak · Aug 09, 2017 at 10:22 PM · c#scripting problemuicanvasinventory

Close UI using Canvas Group

Issue:

I'm working with UI in my game (Don't Die, name will probabbly change). I need to be able to open and close menus in some specific situations. "So," - I thought - "why not to make a universal script using Canvas Group? It will save me from a lot of headaches!"...

I have only one problem. With my script, I'm able to open the... Inventory, let's say. But, unless I use a close UI.Button for it, I'm not able to close the "Inventory" by pressing any key on the keyboard.


How do I do it:

When I'm closing I set CanvasGroup.alpha to zero, so the menu gets invisible, CanvasGroup.blockRaycasts to false, so it don't block other menus and CanvasGroup.interactable to false, so the player can't click in anything on it.

To open I just do the same thing, but in the oposite direction.

But if I open the menu it doesn't close again. Unless I make a close button.


What I've already tried?

  • I've tried to make Open() and Close() IEnumerators, instead of voids, but with no success.

  • Writing the whole open/close code inside the ifs doesn't work as well.

  • Removing the Draggable-related pieces.

  • Other stuff I don't remember by now. (Way too many things...)


The Script:

https://0bin.net/paste/ZlOsi+ydMBlBgMNP#-hO01knc97WAOmJLT3pqhkbYtqGnFt5bdKjIt8RylOE


Conclusion:

I don't get any exeptions, any warnings or anything about this. And I haven't found an answer on Google as well. If someone could figure out why this doesn't work I would be gratefull. Thanks.


It's a shame that Unity Answers doesn't even have a topic/tag about it.

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

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by ShadyProductions · Aug 10, 2017 at 12:37 PM

In your startclosed you set state to false if start closed is true

then when you press the button you do

state = !state;

so state becomes true;

then when state is true you call Close();

and in close you set state to false

So next time you click, state wil again be turned true and call close again.

You're stuck in that loop there. Thats your issue.

So instead of in your open() and close()

Edit: remove state = !state; from the update and it should work.

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 Igor_Vasiak · Aug 10, 2017 at 12:46 PM 0
Share

Okay, I'll try ro fix this once I get to my computer. Thanks.

avatar image ShadyProductions Igor_Vasiak · Aug 11, 2017 at 08:31 AM 0
Share

Did you get it working?

avatar image Igor_Vasiak ShadyProductions · Aug 11, 2017 at 02:42 PM 0
Share

Yep! Thanks!

Follow this Question

Answers Answers and Comments

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

Unity 2D Combat Text Issue With Multiple Enemies 2 Answers

UI Canvas Image parented to main camera only moves in x and z 0 Answers

How to send mouse events directly to the canvas in world pos 0 Answers

Multiple Cars not working 1 Answer

How to get the GameObject in a callback function 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