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
2
Question by Trevor 1 · Mar 29, 2010 at 09:52 AM · children

Activate children

Okay I have pretty much what I needed done so far, and Now I just need to know what the complete script is to activate or deactivate the children from a game object. If you know please tell me I have only 2 weeks left to get this project DONE!

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

2 Replies

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

Answer by duck · Mar 29, 2010 at 10:52 AM

There's a built-in function in the Unity API to do this for you:

GameObject.SetActiveRecursively

(note, this activates/deactivates the children and the object itself - i.e. not just the children)

Comment
Add comment · Show 3 · 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 Giantbean · Oct 23, 2013 at 06:17 PM 0
Share

How is this done in Unity 4 now that SetActiveRecursively is depreciated?

avatar image Basez64 · Oct 23, 2013 at 06:42 PM 0
Share

gameObject.SetActive(false) is the new version, which disables the gameobject + all of its children

avatar image Giantbean · Oct 23, 2013 at 08:47 PM 0
Share

Yes Basez64 that will deactivate everything but the reverse gameObject.SetActive(true) is not reactivating.

Rutter expalined in another post how to loop through and reactivate the children.

 GameObject $$anonymous$$yObjName = GameObject.Find("ObjName");
                        foreach (Transform child in $$anonymous$$yObjName.transform)
                     {
                             child.gameObject.SetActive(true);
                     } 

However I cant get this to work. ($$anonymous$$ay be an NGUI issue)

Edit-- Yep NGUI uses:

NGUITools.SetActiveChildren($$anonymous$$yObjName, true);

It would have been nice if they had made this clear to its users, otherwise its a great tool.

avatar image
0

Answer by Imagineum · Aug 29, 2014 at 07:26 PM

I did it that way and it works but my child does't move anymore.

Here's a code that disable my additional enemy on start and reactivate it when player has 200 points.

 using UnityEngine;
 using System.Collections;
  
 public class EnemyActivatorController2 : MonoBehaviour {
  
     // Use this for initialization
     void Start () {
         GameObject ActiveEnemy2 = GameObject.Find ("EnemyActivator2");
         foreach (Transform child in ActiveEnemy2.transform) {
                         child.gameObject.SetActive (false);
                 }
  
  
     }
  
     // Update is called once per frame
     void Update () {
         if (PlayerController.Points == 200) {
             GameObject ActiveEnemy2 = GameObject.Find ("EnemyActivator2");
             foreach (Transform child in ActiveEnemy2.transform) {
                 child.gameObject.SetActive (true);
             } 
         }
  
     }
 }

It working but my additional enemy spawn and doesn't move anymore.

Here is enemy script:

using UnityEngine; using System.Collections;

public class EnemyController2 : MonoBehaviour {

 public float speed = -1;
 private Transform spawnPoint;
 
 // Use this for initialization
 void Start () {
     spawnPoint = GameObject.Find("SpawnPoint").transform;
     rigidbody2D.velocity = new Vector2 (speed, 0);
 
 
 
 }
 
 // Update is called once per frame
 void Update () {
 
 }
 
 void OnBecameInvisible()
 {
     if (Camera.main == null)
                     return;
 
     float yMax = Camera.main.orthographicSize - 0.5f;
     transform.position = new Vector3( spawnPoint.position.x,
                                      Random.Range (-yMax, yMax),
                                      transform.position.z );
 }
 

}

Any ide how to make he move again?

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 Tyche10 · May 11, 2016 at 08:48 AM 0
Share

Since this question is still unanswered: Your problem is that you only give a velocity to your enemy on initialization. If you want the code to run every time you reactivate the object, you should put it in the OnEnable() function, not the Start() function.

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

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

FInd the min and max position of children? 1 Answer

finding a child object by string 1 Answer

Script sharing 2 Answers

Changing the parent's position based on a child's variable 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