Hi guys, i got a very very strange problem, i create a sphere gameobject,and i can delete it directly, but why does’t work if i add a if statement
//This is work correctly
targets = GameObject.CreatePrimitive(PrimitiveType.Sphere);
targets.transform.position = new Vector3(0, 10, 0);
targets.transform.localScale = new Vector3(Random.Range(1.0f, 5.0f), Random.Range(1.0f, 5.0f), Random.Range(1.0f, 5.0f));
targets.AddComponent(“Rigidbody”);
//add force and direction for the sphere
targets.rigidbody.AddForce(Vector3.down * speed * 1);
destroy(targets,2);
//this not
//The targets
targets = GameObject.CreatePrimitive(PrimitiveType.Sphere);
targets.transform.position = new Vector3(0, 10, 0);
targets.transform.localScale = new Vector3(Random.Range(1.0f, 5.0f), Random.Range(1.0f, 5.0f), Random.Range(1.0f, 5.0f));
targets.AddComponent(“Rigidbody”);
//add force and direction for the sphere
targets.rigidbody.AddForce(Vector3.down * speed * 1);
if(targets.transform.position.y <-5)
destroy(targets,2);
i tried so many different ways, but still not work,really need help. Much thanks for this!!