I have the following script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class movementPoints : MonoBehaviour {
public GameObject[] movpoints;
int current = 0;
float rotSpeed;
public float speed;
float WPradius = 1;
void Update()
{
if (Vector3.Distance(movpoints[current].transform.position, transform.position) < WPradius)
{
current++;
if (current >= movpoints.Length)
{
current = 0;
}
}
transform.position = Vector3.MoveTowards(transform.position, movpoints[current].transform.position, Time.deltaTime * speed);
}
}
This allows me to pick an amount of waypoints where an object would move, it also includes a speed value.
But my problem is, this speed value is constant, I would like to be able to change the speed from waypoint to waypoint, like going from A to B with speed 5, but from B to C with speed 10, how can I do this?