Skip to content

Instantly share code, notes, and snippets.

@gastoncaminiti
Last active April 25, 2025 16:33
Show Gist options
  • Save gastoncaminiti/d64230033c6506e508f94db64568b552 to your computer and use it in GitHub Desktop.
Save gastoncaminiti/d64230033c6506e508f94db64568b552 to your computer and use it in GitHub Desktop.
Fundamentos de NavMesh - Programacion 3 Clase 03 [Patrullar]
using UnityEngine;
using UnityEngine.AI;
public class Patrullaje : MonoBehaviour
{
[SerializeField] private Transform[] puntos;
private int indiceActual = 0;
private NavMeshAgent agente;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
agente = GetComponent<NavMeshAgent>();
if (puntos.Length > 0)
{
IrAlPuntoActual();
}
}
void Update()
{
if (!agente.pathPending && agente.remainingDistance < 0.2f)
{
AvanzarAlSiguientePunto();
}
}
void IrAlPuntoActual()
{
agente.SetDestination(puntos[indiceActual].position);
}
void AvanzarAlSiguientePunto()
{
indiceActual = (indiceActual + 1) % puntos.Length;
IrAlPuntoActual();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment