public IEnumerator OffsetPursuitState()                                                                                                      //used to pursue
    {
        Debug.Log("Offset Pursuit: ENTER");                                                                                                      //log entering this state

        flock.behaviour = OffsetPursuitBehaviour;                                                                                                //set the correct behaviour

        prepareAttackTimer = prepareAttackTimeValue;                                                                                             //set the prepare attack timer

        while (predatorState == PredatorStates.OffsetPursuit)                                                                                    //while we are in pursuit
        {
            foreach (FlockAgent agent in flock.agents)                                                                                           //for each of the agents in our flock
            {
                List <Transform> filteredContext = (contextFilter == null) ? flock.areaContext : contextFilter.Filter(agent, flock.areaContext); //make a list of agents nearby from other flocks

                if (filteredContext.Count <= 0)                                                                                                  //if there are no enemies nearby
                {
                    predatorState = PredatorStates.WanderSeek;                                                                                   //change back to wander
                }
            }

            if (prepareAttackTimer <= 0 && !isAttacking) //if we are ready to attack and arent already attacking
            {
                predatorState = PredatorStates.Attack;   //change to attack state
            }

            yield return(null); //return out of the while loop
        }

        Debug.Log("Offset Pursuit: EXIT");       //log exiting the state
        ChangeStateTo(predatorState.ToString()); //change state
    }
    public IEnumerator AttackState()                                                                                                             //used to attack
    {
        Debug.Log("Attack: ENTER");                                                                                                              //log entering the state

        flock.behaviour = AttackBehaviour;                                                                                                       //set the behaviour

        prepareAttackTimer = prepareAttackTimeValue;                                                                                             //reset the prepare timer
        isAttacking        = true;                                                                                                               //we are now attacking
        maxAttackTimer     = maxAttackTimeValue;                                                                                                 //start the max attack timer

        while (predatorState == PredatorStates.Attack)                                                                                           //while we are attacking
        {
            foreach (FlockAgent agent in flock.agents)                                                                                           //for each agent in our flock
            {
                List <Transform> filteredContext = (contextFilter == null) ? flock.areaContext : contextFilter.Filter(agent, flock.areaContext); //make a list of agents nearby from other flocks

                //? KILLING // functionality for killing the enemies that was extra and causing bugs so it was sadly taken out due to a lack of time

                /** int randomAgent = Random.Range(0, filteredContext.Count - 1);
                 *
                 * for (int i = 0; i < filteredContext.Count; i++)
                 * {
                 *  FlockAgent flockAgent = filteredContext[i].gameObject.GetComponent<FlockAgent>();
                 *
                 *  if (flockAgent != null && i == randomAgent)
                 *  {
                 *      flockAgent.Die();
                 *      print("killed agent No: " + i);
                 *  }
                 * }*/

                if (filteredContext.Count <= 0)                //if there are no enemies nearby
                {
                    isAttacking   = false;                     //we are no longer attacking
                    predatorState = PredatorStates.WanderSeek; //change to wander state
                }
            }

            yield return(null); //return out of the while loop
        }

        Debug.Log("Attack: EXIT");               //log exiting the state
        ChangeStateTo(predatorState.ToString()); //change state
    }
    void Update()
    {
        stateDisplay.text = (stateDisplay != null) ? predatorState.ToString() : null; //Display the state using the text element if it exists

        #region TIMERS
        if (!isAttacking && predatorState == PredatorStates.OffsetPursuit) //if we arent currently attacking and we are in pursuit
        {
            prepareAttackTimer -= Time.deltaTime;                          //Countdown to attacking
        }

        #region Speeding Up
        if (isAttacking && predatorState == PredatorStates.Attack) //if we are attacking and in the attacking state
        {
            maxAttackTimer -= Time.deltaTime;                      //countdown to the end of attacking
            if (!isSpeedy)                                         //if we havent already sped up
            {
                flock.maxSpeed *= speedMultiplier;                 //speed up
                isSpeedy        = true;                            //we are now going faster
            }
        }
        else //otherwise
        {
            flock.maxSpeed = normalSpeed; //set our speed to the normal speed
            isSpeedy       = false;
        }
        #endregion

        if (maxAttackTimer <= 0)                                 //if we are out of attack time
        {
            isAttacking   = false;                               //we are no longer attacking
            predatorState = PredatorStates.WanderSeek;           //set wander state
            ChangeStateTo(PredatorStates.WanderSeek.ToString()); //change to wander state
            maxAttackTimer = maxAttackTimeValue;                 //reset the timer
        }
        #endregion
    }
    // * //
    #region Wander Seek
    public IEnumerator WanderSeekState()                                                                                                         //used to wander
    {
        Debug.Log("Wander: ENTER");                                                                                                              //log entering this state

        flock.behaviour = WanderSeekBehaviour;                                                                                                   //set the correc behaviour

        while (predatorState == PredatorStates.WanderSeek)                                                                                       //while we are in this state
        {
            foreach (FlockAgent agent in flock.agents)                                                                                           //for each of the agents in our flock
            {
                List <Transform> filteredContext = (contextFilter == null) ? flock.areaContext : contextFilter.Filter(agent, flock.areaContext); //make a list of agents nearby from other flocks

                if (filteredContext.Count > 0)                                                                                                   //if there are agents on the list (aka enemies nearby)
                {
                    predatorState = PredatorStates.OffsetPursuit;                                                                                //change to pursuit
                }
            }

            yield return(null); //return out of the while loop
        }

        Debug.Log("Wander: EXIT");               //log the state exit
        ChangeStateTo(predatorState.ToString()); //change state
    }