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 Mol · Mar 11, 2015 at 03:07 PM · guipanel

How To Inactivate Childs of a GameObject (GUI)

Hi, I'm new to Unity and i try to create a menu by using the new GUI (4.6). I want a menu looking like the KeyNote menu, with a panel to the right of the scene which changes when we click one of the buttons.

alt text

All my panels are in a EmptyGameObject. If i inactivate this GameObject i can't activate a specific panel after. My idea was :

  1. Inactivate all the panels to make sure any pre-existent panels are deactivated

  2. Activate the panel linked to the button (with SetActive)

I do not managed to inactivate all the children of the GameObject, any solutions ? If u have a better idea on how to make this kind of menu, feel free to contribute.


Thanks. Please excuse my poor English

menuex.png (30.8 kB)
Comment
Add comment · Show 2
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 AlwaysSunny · Mar 11, 2015 at 03:13 PM 1
Share

If all the panels are the same height, width, and position, (and the only difference is the contents), you might consider swapping out contents ins$$anonymous$$d.

In either case, I think your solution is fine:
OnClick any button...
Disable all panels...
Enable the correct panel.

Create a Panel$$anonymous$$anager script which has a collection of panel (or panel_content) objects. Iterate over this collection to disable all panels. The buttons could pass an integer index to a method on the manager to select the correct panel from the collection.

In what way is this not working out for you?

avatar image Mol · Mar 11, 2015 at 03:54 PM 0
Share

Thanks, i did it this way !

I thought to use the same method but with one panel and several GameObject containing contents, so it will swap out content ins$$anonymous$$d of swapping panels.

2 Replies

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

Answer by fffMalzbier · Mar 11, 2015 at 03:15 PM

You can get the children of your EmptyGameObject and deactivate them one by one. After that you can activate the one you like to have active.

         for (int i = 0; i < transform.childCount; i ++)
         {
             transform.GetChild(i).gameObject.SetActive(false);
         }
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 Mol · Mar 11, 2015 at 04:07 PM

Thanks ! I did something similar and it's working fine.

 public void ActivatePanel(string panelId)
         {
             foreach(Transform child in transform)
             {
                 if(child.name == panelId)
                 {
                     child.gameObject.SetActive(true);
                 }
                 
                 else{
                     child.gameObject.SetActive(false);
                 }
             }
             
         }

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Tutorials for 2D game GUI 2 Answers

Determining if Horizontal Layout Group has room for an element. 0 Answers

Button onClick events will not be triggered 1 Answer

Panels keep disappearing when camera focuses on it 0 Answers

Problem with GUI animation transitioning. 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