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 Jul 15, 2013 at 08:51 PM by davidflynn2 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by davidflynn2 · Jul 15, 2013 at 07:31 PM · c#childactive

Disable child of clicked object

The following script identifies the object I click on and checks the tag on it. Now I am needing to know what I need to add to this to make it find the child game object and turn it off.

Here is the script:

 using UnityEngine;
 using System.Collections;
 
 public class ChangeWeather : MonoBehaviour
 {
     public bool active = true;
     private Transform child;
     
 
     void Update () 
     {
         if(Input.GetMouseButtonDown(0))
         {
              Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                 RaycastHit hit;
             
             if(Physics.Raycast(ray, out hit))
             {
                 if(hit.collider.tag == "WorldBlocks")
                 {
                     
                     if(active == true)
                     {
                                              
                         foreach(Transform child in hit.transform) 
                         {
                                 child.Active = false;//This part is not working.
                         }
 
 
                         active = false;
                     }
                     
                     if(active == false)
                     {
                         foreach(Transform child in hit.transform) 
                         {
                                // child.Active = false; This part is not working
                         }
                         active = true;
                         
                     }
                 }
             }
 
         }
         
     }
 }
 
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 robertbu · Jul 15, 2013 at 07:38 PM 1
Share

Transform.Find()

GameObject.SetActive()

Or maybe you just want to hide the object:

Renderer.enabled

avatar image creighcl · Jul 15, 2013 at 08:28 PM 1
Share

^ In the latest versions of Unity you want to use .SetActive(false) ins$$anonymous$$d of .Active = false. Like Robertbu said, I tend to use child.renderer.enabled = false to hide it, but not disable it

2 Replies

  • Sort: 
avatar image
0
Best Answer

Answer by davidflynn2 · Jul 15, 2013 at 08:50 PM

Ok this ended up working for me:

 if(hit.collider.tag == "WorldBlocks")
                 {
                     
                     if(active == true)
                     {
                                              
                         foreach(Transform child in hit.transform) 
                         {
                                child.renderer.enabled = true;
                         }
 
 
                         active = 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
1

Answer by uskak41kw · Jul 15, 2013 at 07:42 PM

Also u can preSet this child as public GameObject

 public GameObject child; //set it here
 child.SetActive(false);
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 davidflynn2 · Jul 15, 2013 at 07:46 PM 0
Share

The child name will be the same but it could very what child is chose I have a world made up of different grids and I am wanting to be able to click on any of them. All I need it to do is take the object I click on find its child game object and turn it off.

Follow this Question

Answers Answers and Comments

17 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Check if the child of an object is active not working!!! 2 Answers

C# Find component InChildren 3 Answers

How do i make my person move forward in the direction of the cursor 2 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