Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 sovan-k1 · Jan 28, 2016 at 01:32 PM · getcomponentsinchildrenrenderer.enabled

Gameobject with many child objects disable mesh not working.

Hi guys,

Now this is already a discussed topic and I still did not get how to solve the issue.

Problem:

I have an architectural building with many child game objects in it. Some having renderer and some gameobjects(without renderer) having further child objects which in return has more children. So I want to make the whole building invisble in a click of Button1 and make it visible again on clicking Button2. I have written the following code but it does not works.

using UnityEngine; using System.Collections;

public class ActionScriptChangeVisibility: MonoBehaviour

{

 public Renderer[] objectHavingChild;

 public void InvisibleBeacon() //Button1
 {
     objectHavingChild = GetComponentsInChildren<Renderer>();
     foreach (Renderer rend in objectHavingChild)
         rend.enabled = false;    
 }

 public void VisibleBeacon() //Button2
 {
     objectHavingChild = GetComponentsInChildren<Renderer>();
     foreach (Renderer rend in objectHavingChild)
         rend.enabled = true;    
 }

}

Question: This script is attached to the buttons. I don't get how to disable a particular parent game object along with child. How do I make the whole building invisible? In this code there is no option to select the particular gameobject to make it invisble. Any help is appreciated.

Thanks in Advance.

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 VivienS · Jan 28, 2016 at 01:43 PM 0
Share

Attach the script component to the root GameObject of your building ins$$anonymous$$d of your button and reference it with the button' OnClick action (assu$$anonymous$$g you are using the new Unity UI: http://docs.unity3d.com/$$anonymous$$anual/script-Button.html).

avatar image VivienS · Jan 28, 2016 at 01:49 PM 0
Share

And just a tip: I think you will get the same behavior with much less hassle if you deactivate the root GameObject (root.SetActive(false)) ins$$anonymous$$d of all children's renderer components?

avatar image sovan-k1 VivienS · Jan 28, 2016 at 04:07 PM 0
Share

Okay thanks @VivienS I will try.

0 Replies

· Add your reply
  • Sort: 

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

34 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

Related Questions

InvalidCastException when trying to access child components 2 Answers

Visibility based on Tags 2 Answers

Is it possible to start a game and get GUI-button act as like its already pressed? (Javascript) 1 Answer

Cannot cast form source type to destination type? 2 Answers

renderer.enable = photon? 0 Answers


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