I would like to make my NPC idle/stop walking at some chosen waypoints for a few seconds before resuming its path but I have a hard time figuring out how to code it to be able to customize it easily in the Inspector. This is my current Waypoint System script that I attached to my NPC gameobject.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Path : MonoBehaviour
{
public Animator anim;
public Rigidbody2D myRigidbody;
[SerializeField]
float moveSpeed = 2f;
[SerializeField]
Transform[] waypoints = default;
int waypointIndex = 0;
void Start()
{
myRigidbody = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
Vector3 temp = waypoints[waypointIndex].transform.position;
}
void Update()
{
Move();
}
public void SetAnimFloat(Vector2 setVector)
{
anim.SetFloat("input_x", setVector.x);
anim.SetFloat("input_y", setVector.y);
}
public void changeAnim(Vector2 direction)
{
if (Mathf.Abs(direction.x) > Mathf.Abs(direction.y))
{
if (direction.x > 0)
{
SetAnimFloat(Vector2.right);
}
else if (direction.x < 0)
{
SetAnimFloat(Vector2.left);
}
}
else if (Mathf.Abs(direction.x) < Mathf.Abs(direction.y))
{
if (direction.y > 0)
{
SetAnimFloat(Vector2.up);
}
else if (direction.y < 0)
{
SetAnimFloat(Vector2.down);
}
}
}
public void Move()
{
Vector3 temp = Vector3.MoveTowards(transform.position, waypoints[waypointIndex].transform.position, moveSpeed * Time.deltaTime);
changeAnim(temp - transform.position);
myRigidbody.MovePosition(temp);
if (temp == waypoints[waypointIndex].transform.position)
{
waypointIndex += 1;
}
if (waypointIndex == waypoints.Length)
{
waypointIndex = 0;
}
}
}



