Greetings!
Im making a script where I make other gameobjects of a certain class (Shapes) a child of one parent.
My next goal is to destroy the children, one second after another, in a coroutine, using the for loop.
I do have my scripts attached to the gameobjects, so its down to the for loop and coroutine.
Could someone point out what my mistake is, and or give me advice on other parts of the scritpt?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ShapeParenter : MonoBehaviour
{
const string SHAPE_PARENTER = "Shape Parenter";
Shape[] shapes;
int shapeDestroyTime = 1;
private void Awake()
{
gameObject.name = SHAPE_PARENTER;
shapes = FindObjectsOfType<Shape>();
Debug.Log("Number of Shapes: " +shapes.Length);
foreach (Shape shape in shapes)
{
shape.transform.parent = gameObject.transform;
}
}
private void Start()
{
StartCoroutine(DestroyChildren(shapeDestroyTime));
}
IEnumerator DestroyChildren(int destroyTimer)
{
for (int i = 0; i > shapes.Length; i++)
{
Destroy(shapes*.gameObject);*
yield return new WaitForSeconds(destroyTimer);
}
}
}