Головна‎ > ‎Unity‎ > ‎

Рух по маршруту

public GameObject[] waypint;
public int num = 0;
public float minDist;
public float speed;
public bool rand = false;
public bool go = true;

void Update () {
float dist = Vector3.Distance(gameObject.transform.position,waypint[num].transform.position);
if(go == true)
{
if(dist>minDist)
{
Move();
}
else
{
if(rand == false)
{
if(num+1 == waypint.Length)
{
num = 0;
}
else
{
num++;
}
}
else
{
num = Random.Range(0, waypint.Length);
}
}
}
}

public void Move(){
gameObject.transform.LookAt(waypint[num].transform.position);
gameObject.transform.position += gameObject.transform.forward*speed*Time.deltaTime;
}