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 /
This question was closed Mar 19, 2013 at 06:54 AM by sona.viswam for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by sona.viswam · Jan 30, 2013 at 05:56 AM · disableparenting

Disable child with name of a specific object

 Using instantiate i had created obj1, obj2, obj3...
 All these objects have child with similar names roof, wall etc.
 if the character collide with a specific object,
 eg : obj1
 i just want to disable only roof(a child) of obj1 
 and not complete obj1 without using below code
 var renderers = GetComponentsInChildren(Renderer);
 for (var r : Renderer in renderers) {
     r.enabled = false; 
 }
 for loop takes more time.
 any other easy way to disable .
 Thanks in advance.
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
0
Best Answer

Answer by liszto · Jan 30, 2013 at 06:27 AM

I'm not really sure of what you want but just to be sure I gonna give you more solutions :

First you say when the player player hit one of this object, I want to disable this object but in your example you say the roof which is a child of the object collide.

So do you want disable the global object or just the roof if the player collide with the roof ?

Then you say disable but enabled just hide the renderer of the object so you just wanna hide it or totally disable it ?

If in your object each child have his own collider you can do this :

 function OnCollisionEnter(collision : Collision)
 {
     collision.gameObject.active = false;

     //Or if it's just graphic you can do this
     collision.gameObject.renderer.enabled = false
 }



If you want disable all objects of the collided object you can do this :

 function OnCollisionEnter(collision : Collision)
 {
     //This don't just hide them but disable them and it's obviously a function that hide a loop
     collision.gameObject.SetActiveRecursively( false );
 }

But without a loop I don't think you can disable the childs of an object without a loop to iterate on them

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

Follow this Question

Answers Answers and Comments

10 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

Related Questions

A node in a childnode? 1 Answer

Disable frames skipping 0 Answers

Unity 3.0 Water Shader Shadow Problem 0 Answers

Disable a GameObjects scripts knowing only the GameObjects name 3 Answers

Strange GOs Bounce after parenting 2D game 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