Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Last active April 2, 2017 16:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsubaki/301d163cab865ad8fa17 to your computer and use it in GitHub Desktop.
Save tsubaki/301d163cab865ad8fa17 to your computer and use it in GitHub Desktop.
UnityのNavmesh Agentで巡廻させるコード
using UnityEngine;
using System.Collections;
public class Patrol : MonoBehaviour {
public Transform[] wayPoints;
public int currentRoot;
void Update ()
{
Vector3 pos = wayPoints[currentRoot].position;
if(Vector3.Distance(transform.position, pos) < 0.5f)
{
currentRoot = (currentRoot < wayPoints.Length - 1) ? currentRoot + 1 : 0;
}
GetComponent<NavMeshAgent>().SetDestination(pos);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment