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 Yuschick · Dec 11, 2014 at 04:10 PM · checkbox

How to use GetChild in Loops and Traversing

Hello. I am working on a basic feature but am having trouble with the logic needed.

I have five buttons, and when you click on Three, it is set to active as well as the previous two. When you click on Five all five are active. Then when you click back on Two, only the first two are active.

So what I have in mind is taking the ID of the selected button and reference that in a for loop to set the previous children to active and the following children as inactive.

My hierarchy is as follows:

Datamarks Block - DatamarksOne - Checkbox - DatamarkTwo - Checkbox ...

So if I click on the Third datamark, how can I find the other children checkboxes to adjust their alpha property?

 for (var x : int = 0; x < value; x++) {

}

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

· Add your reply
  • Sort: 
avatar image
0

Answer by NoseKills · Dec 11, 2014 at 05:06 PM

You are not saying how you keep track of the clicked button etc. but the optimal situation would be for example to have all buttons in an array and the clicked button in a variable:

 GameObject[] allButtons;
 
 void setButtonStates(GameObject pressedButton)
 {
     bool found = false;
     for (var x : int = 0; x < allButtons.Length; x++) 
     {
         if (found)
         {   
             // clicked button was found earlier. 
             // This is a button after the selected one
             // set allButtons[x] to unselected state
         }
         else // !found
         {
             // clicked button is still ahead or this one
             // adjust alpha of allButtons[x] to selected value
         }
 
         found = allButtons[x] == pressedButton;
     }
 }
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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Menu Items as checkboxes/radio buttons 4 Answers

Physics.CheckBox() Alternatives 0 Answers

how to create checkbox preference regarding image effects?? 0 Answers

C# Script Haven't Check Box 2 Answers

CheckBox in unity3d 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