Need help with multiple patrols on a AI, looping.

So i figured out how to switch from a randomized navamesh patrol to a flying patrol. But i haven’t been able to reset it and make it into a constant loop, anyone have any advice how to accomplish this? Also it says that “Array index is out of range” when it gets to the end of the all the currentpatrolpoints. It says this line is causing it,Quaternion rotation = Quaternion.LookRotation(Patrolpoints[CurrentPatrolpoint].transform.position - transform.position);

using UnityEngine;
using System.Collections;

public class MosquitoAI : MonoBehaviour
{
public GameObject Patrolpoints;
public GameObject waypoints;
public Transform player;

NavMeshAgent NavMeshA;

public int MaxPatrolpoints;

public float Timer = 500;

public float Distance;
public float Turnamount;
public float Forwardamount;
public float Speed;
public float TravelSpeed;
public float Damping;
public float TimeDamper;

public int CurrentWaypoint;
public int CurrentPatrolpoint;

public bool flymode;
public bool Looper;

void Awake()
{
	NavMeshA = GetComponent<NavMeshAgent>();
	NavMeshA.updatePosition = true;
	NavMeshA.updateRotation = true;
	
	waypoints = GameObject.FindGameObjectsWithTag("WaypointMosquito");
	CurrentWaypoint = Random.Range (0, waypoints.Length); 

	Looper = false;
}

void Update()
{
	Timer--;

	if(Timer <= 0)
	{
		flymode = true;
	}
	else
	{
		Ground();
		NavMeshA.enabled = true;
	}
	if (flymode == true) 
	{

		NavMeshA.enabled = false;
		Flying();
	}
}

void Ground()
{
	NavMeshA.speed = Speed;
	
	if(Vector3.Distance(this.transform.position, waypoints[CurrentWaypoint].transform.position) >= 2)
	{
		NavMeshA.SetDestination(waypoints[CurrentWaypoint].transform.position);
		MovementManager(Vector3.zero);
	}
	else if(Vector3.Distance(this.transform.position, waypoints[CurrentWaypoint].transform.position) <= 2)
	{
		CurrentWaypoint = Random.Range (0, waypoints.Length);
	}
	else
	{
		MovementManager(Vector3.zero);
	}
}

void Flying()
{ 

	if(Vector3.Distance(this.transform.position, Patrolpoints[CurrentPatrolpoint].transform.position) <=2)
	{
		CurrentPatrolpoint ++;
	}
	if(CurrentPatrolpoint >= Patrolpoints.Length) 
	{
			Debug.Log ("working");
			flymode = false;
			NavMeshA.enabled = true;
			Ground();
	}

	Quaternion rotation = Quaternion.LookRotation(Patrolpoints[CurrentPatrolpoint].transform.position - transform.position);
	transform.rotation = Quaternion.Slerp (transform.rotation, rotation, Time.deltaTime * TimeDamper);
	
	transform.Translate (Vector3.forward * TravelSpeed * Time.deltaTime);
	MovementManager(Vector3.zero);
}

void MovementManager(Vector3 move)
{
	if(move.magnitude < 1f)move.Normalize();
	move = transform.InverseTransformDirection(move);
	Turnamount = Mathf.Atan2 (move.x, move.z);
	Forwardamount = move.z;
}

}

You dont reset the currentpatrolpoint properly. On line 60 you need to add something like:

if(currentPatrolPoint >= patrolPoints.Length-1) {
    currentPatrolPoint = 0;
} else if(currentPatrolPoint < 0) {
    currentPatrolPoint = patrolPoints.Length-1
}
    
    //Set waypoint

Remember that array.Length will return the amount of things in the array, not the index. So array[array.Length] doesn’t exist. That is usually why people get that error.