waypoint set switching

i have a movement script that uses waypoints to tell the characters where to go and i want to adapt it so i can switch the units to a different set of waypoints with a GUI button. ie for changing a group to go down a different path.

how would i go about making this?

included below is a copy of the waypoint script if that will help.

var waypoint : Transform[];
var speed : float = 20;
private var currentWaypoint : int;
var loop : boolean = true;


function Update(){
	if(currentWaypoint < waypoint.length){
		var target : Vector3 = waypoint[currentWaypoint].position;
		var moveDirection : Vector3 = target - transform.position;
		
		var velocity = rigidbody.velocity;
		
		if(moveDirection.magnitude < 1){
			currentWaypoint++;
		}
		else{
			velocity = moveDirection.normalized * speed;
		}
	}
	else{
		if(loop){
			currentWaypoint=0;
		}
		else{
			velocity = Vector3.zero;
		}
		
	}
	
	rigidbody.velocity = velocity;
	transform.LookAt(target);
}

Make a function that accepts an array of positions and then moves your gameobject through them accordingly.

I’m quite new to unity and very limited coding experience before, and none with java, so i have no idea how i would make them.
I believe i have an array for the waypoints already but what i want to have in the end is have groups spawning, heading down paths but change paths at certain points via a GUI button or something.
so i don’t think what your saying is quite what I’m looking for at the moment, though please correct me if I’m not understanding correctly

What i meant in the above post is, array of positions is a predefined path and if you can make a function that can interpret this predefined path and move your entity accordingly, your problem will be solved.

You should learn c# as fast as you can before you dive into complex stuff then.

I’m really not understanding what you are getting at. I know an array of positions is a predefined path, i already have that in the script in the first post. what i want to find out is how to get it to switch from following one array to following another while the game is playing.

You may want to switch over to a pathfinding solution such as A* or something smiliar.

To answer your question:

my1stPath = some array[ ]
my2ndPath = some array[ ]
.
.etc
arrayToFollow = my1stPath
update() {
if (something happened and i want to change path) {
arrayToFollow = my2ndPath
}
functionThatLoopsArrayToFollow()
}

functionThatLoopsArrayToFollow(arrayToFollow) {
Do stuff
}

I have looked at A* but what i run into the same problem of how do i switch to the other path when i want to.

Obviously I’m very bad at coding and i do thank you very much for your help

if you (or anyone else) would know how to make the A* do what i want i would love to hear it.