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 Smujukia · Mar 29, 2019 at 04:34 AM · coroutinechildrensetactiveforeachforloop

Load Children One at a Time

Hi, I'd like to load each child of an object one at a time after an event has taken place. So far I'm only able to set the parent game object active but would like another effect, please help!

 void Start ()
 {
     _clickanddragscript._OnMouseUp = false;
     lineParent.SetActive(false);
 }
 
 void Update () {

     if (firstBar.transform.position != Vector3.zero)
     {
         Debug.Log("HasChanged");

         if (_clickanddragscript._OnMouseUp)
         {
             Debug.Log("Mose"); 
             firstBar.transform.DOMove(new Vector3(0, 10.9f), 2, false); 
             GetMyChildren(); 

         }
         
         // Wait 1 second 
         // Move the bar up 
         // Add some indication juice 
         // Load all the children of red lines parent object and wait a little between each load 
     }
     
 }

 void GetMyChildren()
 {
     foreach (Transform child in lineParent.transform)
     {

         for (int i = 0; i < barArray.Length; i++)
         {
         
             lineParent.SetActive(true);
                             // maybe do a coroutine 


         }
         
         
     }

     
 }
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 xxmariofer · Mar 29, 2019 at 10:55 AM 0
Share

whats the other effect that you want to achieve? you have not telled us

avatar image Smujukia · Mar 29, 2019 at 04:38 PM 0
Share

Oh, it's in the update function already. It's just if player has clicked and let go of mouse, move another object to a position. Now I need help loading all children of a parent one at a time.

avatar image xxmariofer Smujukia · Mar 29, 2019 at 04:43 PM 0
Share
 foreach (Transform child in lineParent.transform){ child.gameObject.SetActive(tue);}

this?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by David_Rios · Mar 29, 2019 at 07:02 PM

Instead of creating a function for GetMyChildren() you can make a coroutine. It'd be a much cleaner way of activating all your children one-by-one.

This function would activate one of lineParent's children after a certain delay of seconds; I believe this is the effect you want.


Here's an example of a way you could do so with an adjustable time delay:

 IEnumerator GetMyChildren(float delay)
 {
      lineParent.SetActive(true);
 
      foreach (Transform child in lineParent.transform)
      {
            yield return new WaitForSeconds(delay);
 
            child.SetActive(true);
      }
 }



If you wanted a delay of one second, for example, you could call the function in your 'if' statement in the Update function like this: StartCoroutine(GetMyChildren(1f));


Sorry if I misjudged what effect you wanted to achieve, if so, I'll fix my answer, just specify below in a comment.

Comment
Add comment · Show 2 · 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 Smujukia · Mar 30, 2019 at 10:17 PM 0
Share

Thanks @BDCakerules! This was helpful. The thing I noticed is that I had to change the child from a transform to a gameobject to set it active, but it didn't work so I did it manually ins$$anonymous$$d and it worked!

IEnumerator NewGet$$anonymous$$yChildren() {

     for (int i = 0; i < all$$anonymous$$yChildren.Length; i++)
     {
         yield return new WaitForSeconds(delayTime);
         lineParent.SetActive(true);
         all$$anonymous$$yChildren[i].SetActive(true);
     }
     
 }
avatar image David_Rios Smujukia · Mar 30, 2019 at 10:31 PM 0
Share

@Smujukia, ins$$anonymous$$d of changing the child you can just access its gameObject component with .gameobject: Ex:


all$$anonymous$$yChildren[i].gameObject.SetActive(true);


This will work even if your children are transforms. If my answer helped, please mark it as correct! I'm happy you're getting the effect you want.

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

111 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Foreach loop trying to grab all children in scene 1 Answer

How to destroy children one after another in a coroutine, but with a for loop. 1 Answer

[SOLVED]Coroutine method called in OnCollisionEnter() not being called for each collision on chronological order ?! 1 Answer

Make a platform disappear after the next one appear 2 Answers

Unity detects three children of the current object, but only grabs one 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