Last active
April 25, 2025 16:33
-
-
Save gastoncaminiti/d64230033c6506e508f94db64568b552 to your computer and use it in GitHub Desktop.
Fundamentos de NavMesh - Programacion 3 Clase 03 [Patrullar]
This file contains hidden or 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 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