Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Mar 16, 2015 at 01:18 AM by KnightRiderGuy for the following reason:

The question is answered, right answer was accepted

avatar image
5
Question by KnightRiderGuy · Mar 08, 2015 at 03:32 PM · uibuttonsbuttonstates

How To Get UI Button To Stay In A Pressed State

OK this is one of those things about the new UI system that just drives me outright nuts as to why there does not seem to be a built in way to do this. But what if I want a state of the button to stay pressed until clicked again? Is there some built in way to do this that I am missing or do you have to code this somehow?

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
5
Best Answer

Answer by DiegoSLTS · Mar 08, 2015 at 03:42 PM

There is a way to do that with Unity UI. What you're describing is a Toggle, not a Button.

http://docs.unity3d.com/Manual/script-Toggle.html

Comment
Add comment · Show 14 · 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 KnightRiderGuy · Mar 08, 2015 at 04:01 PM 0
Share

Perfect!! Thanks DiegoSLTS, I have been trying to figure out how to get that effect fro a while, I'm hoping I can still get a sound to play when the toggle is set to on or off as in a tone for each click that is to say ;)

avatar image Mmmpies · Mar 08, 2015 at 04:29 PM 0
Share

You can do this with a button as well. In the OnClick call a public function that just sets a bool to the opposite of itself.

 public void ShiftClicked()
 {
     shiftOn = !shiftOn;
     if (shiftOn)
         ShiftImage.color = Color.gray;
     else
         ShiftImage.color = Color.white;
 }

I use this in a keyboard script to set shift on/off.

avatar image KnightRiderGuy · Mar 08, 2015 at 05:15 PM 0
Share

I'm a little confused as to exactly HOW the toggle button actually turns something on or off depending on it's state??

avatar image DiegoSLTS · Mar 08, 2015 at 05:56 PM 0
Share

What do you mean by turning something on and off? The toggle just have a state of pressed (it's "isOn" property), you turn something on and off using that value, but you have to code what it means to have a toggle checked or unchecked.

When you have to select the fuction that receives on bool parameter to be called for that event you'll find the function at the top in the "Dynamic bool" section, and the fuction at the bottom in the "Static paremeters" section. When you choose the dynamic option, the function receives the new value of the toggle (if you checked it, the parameter would be true). When you choose the static option the value the function receives is the one you set in the inspector.

avatar image KnightRiderGuy · Mar 08, 2015 at 06:24 PM 1
Share

I'm not sure I follow. I have a microphone script that I simply want to enable and disable with the same button. I think I am missing something simple on how toggles work but I'm not seeing it. A freaking tutorial on these blasted buttons would be nice somewhere but I have had no luck finding one.

alt text

screen-shot-2015-03-08-at-12133-pm.png (136.2 kB)
screen-shot-2015-03-08-at-12154-pm.png (114.9 kB)
Show more comments

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

Toggles ToggleGroups highlighting problem. 1 Answer

Buttons on mobile activating OnHighlight Animation without touching them. 0 Answers

Highlight button via script at runtime 5 Answers

How to handle button highlighted state on Android with touch/mouse/controller? 0 Answers

How do I highlight multiple buttons at once? 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