how to destroy child object after some position reach?
i make empty object (and instantiate some prefab) from the position of other empty object and then give the empty obejct force to move.
i want to destroy this moved empty object (and their child prefab) after some postion reach, just like some bullet being shoot i need to destroy it or else there will be soo many empty object lying around
here my code
void Update()
{
if (Input.GetKeyUp("space")==true)
{
spawn();
}
if (GetComponentInChildren<Transform>().position.z == 3)
{
Debug.Log("ye");
}
void spawn()
{
GameObject tempempty = new GameObject("basis");
tempempty.AddComponent<Rigidbody>();
tempempty.GetComponent<Rigidbody>().useGravity = false;
tempempty.transform.SetParent(this.transform);
for (int x = 0; x < luas.x; x++)
{
GameObject tempbasisy = Instantiate(basis);
tempbasisy.transform.SetParent(tempempty.transform);
tempbasisy.transform.position = new Vector3(x, 0, 0);
}
tempempty.GetComponent<Rigidbody>().AddForce(0, 0, 100);
}
im sorry i ask this basic question, im new to coding and unity