void Update() { IEnumerator <CarManager.Car> carsIE = cars.GetEnumerator(); while (carsIE.MoveNext()) { carsIE.Current.entity.transform.position += carsIE.Current.velocity * Time.deltaTime; if (carsIE.Current.entity.transform.position.z < player.transform.position.z - 60) { GameObject.Destroy(carsIE.Current.entity); cars.Remove(carsIE.Current); } } /* * for (int i = 0; i < cars.size; i++) * { * cars[i].entity.transform.position += cars[i].velocity * Time.deltaTime; * if (cars[i].entity.transform.position.z < player.transform.position.z - 30) * { * GameObject.Destroy(cars[i].entity); * cars.RemoveAt(i); * } * } */ }
public static void DeleteAllBckgrndCars() { IEnumerator it = cars.GetEnumerator(); while (it.MoveNext()) { GameObject.Destroy(((BckgrndCar)it.Current).gameObject); } cars.Clear(); }