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 

		}
		
		
	}

	
}

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.