• 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 Feb 11, 2016 at 01:44 PM by meat5000 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by KnightRiderGuy · Feb 11, 2016 at 12:19 AM · c#uibuttonstoggletoggle button

Do Something ONLY when all Toggles are On or Off

Is there a way to do somet$$anonymous$$ng ONLY when all three toggles are either on or Off?

My problem is that I have three toggles that are set up like t$$anonymous$$s, I also have another toggle that serves as an indicator light that I want the light/toggle to go off when the last toggle is turned off but turn On when any of the toggles are turned on.... not sure if that makes sense?

 //Activate Audio Button
      public void SIDaudioButtonOnOff (){
          SIDAudioState = ! SIDAudioState;
          if (SIDAudioState == true) {
              toggleSIDindicator = GameObject.Find ("ToggleMainIndicatorLight").GetComponent<UnityEngine.UI.Toggle> ();
              toggleSIDindicator.isOn = true;
          }else {
              SIDAudioState = false;
  
          }
      }
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 saschandroid · Feb 11, 2016 at 12:00 PM 0
Share
avatar image meat5000 ♦ saschandroid · Feb 11, 2016 at 12:04 PM 0
Share
avatar image saschandroid meat5000 ♦ · Feb 11, 2016 at 12:17 PM 0
Share

4 Replies

  • Sort: 
avatar image
0
Best Answer

Answer by ItsIcear · Feb 11, 2016 at 11:00 AM

 if (!toggle && !toggle2 && !toggle3 && !toggle4)
 {
       // Function
 }
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 KnightRiderGuy · Feb 11, 2016 at 01:23 PM 0
Share
avatar image
1

Answer by meat5000 · Feb 11, 2016 at 12:20 AM

Yes. Use an if statement. I used int instead of bools. Seemed easier.

  using UnityEngine;
  using System.Collections;
  
  public class ToggleTest : MonoBehaviour {
  
      public int sw1 = 0;
      public int sw2 = 0;
      public int sw3 = 0;
      public bool indicator = false;
      public int lastCount = 0;
      public int count = 0;
      
      // Update is called once per frame
      void Update () {
      
          if(lastCount == 3 && count == 2 && indicator == true)
          {
              indicator = false;
          }
          else
          {
              if(count == 3)
              {
                  indicator = true;
                  lastCount = count;
              }
              else if(count > 0 && lastCount != 3)
              {
                  lastCount = count;    
              
                  
                  indicator = true;
              }
              else if(count == 0)
              {
                  indicator = false;
                  lastCount = count;
              }
  
              count = sw1 + sw2 + sw3;
          }
      }
  }
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 KnightRiderGuy · Feb 11, 2016 at 12:45 AM 0
Share
avatar image meat5000 ♦ KnightRiderGuy · Feb 11, 2016 at 01:17 AM 0
Share
avatar image meat5000 ♦ KnightRiderGuy · Feb 11, 2016 at 02:05 AM 0
Share
avatar image
1

Answer by Charmind · Feb 11, 2016 at 02:03 PM

Use &&, t$$anonymous$$s is boolean function that returns true if all inputs are true.

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 KnightRiderGuy · Feb 11, 2016 at 12:43 PM

Wow Thanks @meat5000, @ItsIcear, & @saschandroid, I was searc$$anonymous$$ng all over the place for a way to do t$$anonymous$$s, t$$anonymous$$s gives me a lot to try out, I'll see what I come up with today and report back the results.

But just to re cap a little the indicator toggle is just to signal that any of the toggle buttons are ON, That way it means the device is active in some function, by either one or all of the 3 toggle buttons.

BUT if ONLY say one of the toggles is off and the other two are ON then the indicator toggle would need to be ON because it would mean the device is active in some way governed by the 2 toggle being ON.

Now if all toggle are OFF the the device is NOT active in any way so the "Indicator" toggle would then be off.

In my attachment you can see at the top I have an indicator that says Activate/Deactivate and on the bottom I have 3 buttons for "Audio" "Video" and "Heat Sensor" It is these 3 buttons that govern the top indicator being on..... I t$$anonymous$$nk you guys are on the right track with what I'm trying to do though ;) I'll see what I come up with ;)

Screen Cap of My SID Activation Screen


12687853-1053197948035448-131999154987580753-n.jpg (112.9 kB)
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 meat5000 ♦ · Feb 11, 2016 at 01:44 PM 1
Share
avatar image KnightRiderGuy meat5000 ♦ · Feb 11, 2016 at 02:16 PM 0
Share
avatar image meat5000 ♦ KnightRiderGuy · Feb 11, 2016 at 02:52 PM 1
Share

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

93 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

Related Questions

Toggles/Toggle Groups Question 0 Answers

UI Buttons sometimes not detecting touch 1 Answer

Changing multiple toggle states. 0 Answers

Button Scroll view original default button becoming clone 0 Answers

EventSystem.SetSelectedGameObject Does not display highlight animations for my buttons 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