[Solved] GameObject Arraylist Destory Object

I am running into a problem with an Arraylist of GameObjects. I am wanting to destroy one of them when they reach a certain point. I am able to get inside the loop. I am pretty sure it has something to do with minion not being what it is suppose to be or I am using destroy right.

using UnityEngine;
using System.Collections;

public class MinionSpawn : MonoBehaviour {

    public GameObject MinionRed;
    public GameObject MinionBlue;
    public Transform[] waypointsBlue;
    public Transform[] waypointsRed;
    ArrayList MinionsRedList;
    ArrayList MinionsBlueList;
    public Transform StartBlue;
    public Transform StartRed;
    public int MinionPerWave;
    bool gameOver = false;

	// Use this for initialization
	void Start () 
    {
        MinionsBlueList = new ArrayList();
        MinionsRedList = new ArrayList();
        StartCoroutine(MinionTimer());
    }
	
	// Update is called once per frame
	void Update () 
    {
        // working to destory minion if at end waypoint
        foreach (GameObject minion in MinionsRedList)
        {
            //print(minion.transform.position);
            if (minion.transform.position.y > -115)
            {
                print(minion.transform.position);
                Destroy(minion);
            }
        }
        foreach (GameObject minion in MinionsRedList)
        {
            if (minion.transform.position == waypointsRed[waypointsRed.Length-1].position)
            {
                Destroy(minion);
            }
        }
	}

    IEnumerator MinionTimer()
    {
        while (gameOver == false)
        {
            yield return StartCoroutine(MinionSpawner());
            yield return new WaitForSeconds(60);
        }
    }
    IEnumerator MinionSpawner()
    {
        for (int i = 0; i < MinionPerWave; i++)
        {
            GameObject MinionR = (GameObject) Instantiate(MinionRed, StartRed.position, Quaternion.identity);
            GameObject MinionB = (GameObject) Instantiate(MinionBlue, StartBlue.position, Quaternion.identity);
            MinionsRedList.Add(MinionR.gameObject);
            MinionsBlueList.Add(MinionB.gameObject);
            yield return new WaitForSeconds(1);
        }
    }
}

Hi, i just made an example project for you. I hope it help.

Create a new project in Unity
Uncheck Pro Standard(if you are using pro version) and Standard
Goto Assets → Import Package > Select the file > Import
Open the MinionSpot scene on the project folder
Start the game

I commented each step of the scripts.

Sorry about my english.

333797–11730–$minions_203.unitypackage (867 KB)

Thanks that helped a ton.

I’m glad it helped.

Recommendation 1: Check the distance between the waypoint position and minion position and then destroy the minion.

Recommendation 2: Once you instantiated the wave, add each minion of that wave to a group, so later on you can identify to wich group the minion belongs e.g:
for each minion that belongs to group 2 goto this position, for each minion that belongs to group 5 goto that position.

obs: in this exemple find the line(54 and 79): Counter <= MinionsPerWave and change it to Counter <= MinionsPerWave-1 , to solve the problem that create 1 minion more than the specified on the spawner.

Sorry about my english.