中継地点を巡回させる;その1
![Ef28239b 1a59 4329 8c35 ec0d4001f93f](https://codegenius.org/uploads/slide/image/2183/ef28239b-1a59-4329-8c35-ec0d4001f93f.jpeg)
中継地点を巡回させる
using UnityEngine;
using System.Collections;
public class Patrol : MonoBehaviour {
public Transform[] points;
private int destPoint = 0;
private NavMeshAgent agent;
void Start () {
agent = GetComponent<NavMeshAgent>();
agent.autoBraking = false;
GoToNextPoint();
}
void GoToNextPoint(){
if(points.Length == 0)
return;
agent.destination = points[destPoint].position;
destPoint = (destPoint + 1) % points.Length;
}
void Update () {
if(agent.remainingDistance < 0.5f)
GoToNextPoint();
}
}
![91b21517 6158 481e 837f 1ef0cc2a3200](https://codegenius.org/uploads/slide/image/2184/91b21517-6158-481e-837f-1ef0cc2a3200.jpeg)
Unity Code Memo
他のコースを見る![Ef28239b 1a59 4329 8c35 ec0d4001f93f](https://codegenius.org/uploads/slide/image/2183/ef28239b-1a59-4329-8c35-ec0d4001f93f.jpeg)
中継地点を巡回させる
using UnityEngine;
using System.Collections;
public class Patrol : MonoBehaviour {
public Transform[] points;
private int destPoint = 0;
private NavMeshAgent agent;
void Start () {
agent = GetComponent<NavMeshAgent>();
agent.autoBraking = false;
GoToNextPoint();
}
void GoToNextPoint(){
if(points.Length == 0)
return;
agent.destination = points[destPoint].position;
destPoint = (destPoint + 1) % points.Length;
}
void Update () {
if(agent.remainingDistance < 0.5f)
GoToNextPoint();
}
}
![91b21517 6158 481e 837f 1ef0cc2a3200](https://codegenius.org/uploads/slide/image/2184/91b21517-6158-481e-837f-1ef0cc2a3200.jpeg)
中継地点を巡回させる;その1