Hi
I create dynamically a number of GameObject (spheres), and add them to an arraylist at the same time.
private ArrayList wake1 = new ArrayList();
void Update () {
GameObject sphere_1 = GameObject.CreatePrimitive(PrimitiveType.Sphere);
wake1.Add(sphere_1);
DestroyEndWake();
}
void DestroyEndWake() {
if (this.wake1.Count > 20) {
GameObject w = wake1[0];
Destroy(w);
wake1.RemoveAt(0);
}
My goal is to access later on the GameObject to destroy it (I especially want to destroy the older ones).
I get in trouble because when I access an item from this arraylist, it seems like it is not recognized as a GameObject, then I don’t have access to the GameObject method, such as Destroy.
The compiler error for the code above is:
error CS0266: Cannot implicitly convert type object' to
UnityEngine.GameObject’. An explicit conversion exists (are you missing a cast?)
Thanks for your help