Last active
April 2, 2017 16:23
-
-
Save tsubaki/301d163cab865ad8fa17 to your computer and use it in GitHub Desktop.
UnityのNavmesh Agentで巡廻させるコード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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