How to Create a Unique Waypoint List for Each Prefab Unit ??

I wrote this C# script that creates a List of Vector3’s for movement…My NavMeshAgent goes to the first location then the second and then the third and so on. As my agent gets there, it erases each waypoint (no longer needed) and when it gets to the last point, there is nothing left of the list…a simple dynamic list of vector3s. I can add more any time…as many as I wish.

It works fine. HOWEVER…

I was thinking that once I added this script to each of my prefabs, I would be able to provide each prefab with it’s own unique list of waypoints so each of my prefab/navmeshagents could be controlled separately.

But, that’s not how it works. ALL my nav mesh agents go to the same exact waypoints. I’ve been pulling my hair out trying to figure what to add to allow me to give separate waypoints to each prefab unit.

Any help to get my prefabs moving independently would be appreciated.

Thanks.

public class TestNav1 : MonoBehaviour 
{

	Collider sc;
	private bool isSelected = false;
	public NavMeshAgent agent;

	private int wayPoint = 0;

	public List<Vector3> moveToHere = new List <Vector3> ();


	void Update () 
	{

	//////////////////////////////////////////////////  Activates Unit   ///////////////////////////////////////////////////////////////////////////////////////////
		if (Input.GetMouseButtonDown (0))
		{
			Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
			RaycastHit hit;
			 
			if (Physics.Raycast (ray, out hit))
			{
				Collider sc = hit.collider;

				if (sc.gameObject.tag == "Ally" || sc.gameObject.tag == "Supply")
				{
					GameObject[] tempGo;  ////////////////////////////////////////////////////// Next lines through the foreach statement changes color of nonselected items back to blue.  
					tempGo = GameObject.FindGameObjectsWithTag ("Ally");
					foreach (GameObject Ally in tempGo) 
					{
						gameObject.GetComponent<Renderer> ().material.color = Color.blue;
						isSelected = false;
					}

					sc.gameObject.GetComponent<Renderer> ().material.color = Color.cyan;
					agent = sc.GetComponent<NavMeshAgent> ();
					isSelected = true;
				}
			}
		}		//////////   End Unit Selection/activation Logic   ////////////////////////////////////////////////////////////////////////////


		/////////////////////////////////////////////////////////////    Begin Area where you "Click" to add way points.   ////////////////////////////////////////////////////////
		if (Input.GetKey(KeyCode.LeftShift) && Input.GetMouseButtonDown(1) && isSelected == true )
		{
			RaycastHit hit;
			if (Physics.Raycast (Camera.main.ScreenPointToRay(Input.mousePosition), out hit, Mathf.Infinity))
			{

				moveToHere.Add(hit.point);
	
			}
		}////////////////////////////////////////////////////////////////////   End Click to add waypoint area   //////////////////////////////////////////////////////////////////



		if(moveToHere.Count>0) agent.destination = moveToHere [0];

		if (moveToHere.Count>0 && !agent.pathPending && agent.remainingDistance < 0.5f) moveToHere.RemoveAt (0);



	}

}

It depends on how you place them in the world. If the prefabs are created during edit mode you can just edit each prefab individually and that’s it (just don’t apply the changes).
If you instantiate them, the instantiator needs to set the waypoints.

I think I finally figured this out through trial and error…I had been doing a few things wrong and I think I finally got it straightened out.