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 demented_hedgehog · Jun 04, 2015 at 04:02 AM · uibuttongroup

Toggle Group for Buttons?

I'm trying to get toggle-group-like behaviour for a set of buttons.

I can do a certain amount of this in code, there's a state machine behind the buttons and the button states reflect the available actions and the currently selected action for a unit. (Most of the time there'll be a current action, the only time there won't be is when the unit has no actions remaining.. I think that's an unimportant detail as far as this question goes).

The problem occurs when I click somewhere else on the screen and the button gets deselected. Presumably, the UI is deselecting the buttons. How can I stop this?

Comment
Add comment · Show 3
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 Thewhiteaura · Jun 04, 2015 at 04:28 AM 0
Share

$$anonymous$$aybe you can force the game to keep the button selected by coding some more logic, I'm not exactly sure on how you would do this at the moment, but put certain conditions only to de-select? e.g selecting another unit.

avatar image demented_hedgehog · Jun 04, 2015 at 04:31 AM 0
Share

I tried adding an event trigger that would reselect the current button on a Deselect event but it throws an error: "Attempting to select $$anonymous$$oveButton (UnityEngine.GameObject) while already selecting an object." when I do that (presumably this is a mechanism to avoid infinite loops).

avatar image demented_hedgehog · Jun 05, 2015 at 01:37 AM 0
Share

Similar to this question http://answers.unity3d.com/questions/947602/unity5-ui-how-to-trigger-button-click-event-while.html by the looks of it

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by demented_hedgehog · Jun 05, 2015 at 02:42 AM

I'll answer this myself for future readers.

I think I'm trying to do the wrong thing. It doesn't make sense to require the buttons to be selected since that would stop the rest of the UI from working.

Instead I want the button to stay in the pressed state. Unfortunately it doesn't do that so instead you need to roll your own ToggleButton that is a Toggle that looks like a button.

e.g. see here... http://answers.unity3d.com/questions/872667/how-to-make-a-buttons-transition-stay-in-pressed-c.html

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
avatar image
0

Answer by Gilead7 · Oct 17, 2016 at 11:37 PM

A quick and dirty way to do it, if you still have the question is to make two separate canvases. When you click the button, you enable one canvas or the other. Might not quite be what you are looking for, but another possibility.

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
avatar image
0

Answer by biruktes1 · Jan 21, 2021 at 10:59 AM

You can get creative with toggles and toggle group and sprites and an extra UI image element as the child of background. Example: Sequence of toggling toggles in a group and colour tint and arrangement example


screenshot-2021-01-21-104827.png (188.4 kB)
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

23 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

Related Questions

Disable and enable canvas group by pressing an UI button. (C#) 2 Answers

Can't interact with world space ui button when cursor mode is locked any solutions? 1 Answer

Graphics Raycaster - Click on overlapped buttons 1 Answer

Unity5 UI - How to trigger button click event while preventing menu item deselect event? 1 Answer

how to make the button only clickable when clicked in it? (not when clicked on its children for example) 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