using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Ex2 : MonoBehaviour
{
public int n;
public int i;
public GameObject[] runners;
public Transform[] points_runners;
public Vector3 target;
public GameObject runner;
void Start()
{
i = 0;
n = i + 1;
runner = runners[i];
target = points_runners[n].position;
runner.transform.LookAt(target);
}
void Update()
{
if (runner.transform.position == target)
{
runner = runners[Get_runner()];
target = points_runners[Get_Aim()].position;
runner.transform.LookAt(target);
}
Move_to_next();
}
public void Move_to_next()
{
runner.transform.position = Vector3.MoveTowards(transform.position, target, Time.deltaTime * 2f);
}
public int Get_Aim()
{
n = n + 1;
return n;
}
public int Get_runner()
{
i = i + 1;
return i;
}
}
[SerializedField] private Transform target;
[SerializedField] private bool isReadyToRun;
private void OnTriggerEnter()
{
isReadyToRun = !isReadyToRun;
}
private void Update()
{
if (!isReadyToRun) return;
transform.position = Vector3.MoveTowards(transform.position, target, Time.deltaTime * 2f);
}