Noticias

¡RECUERDA QUE SI ERES UN NUEVO USUARIO, DEBES PRESENTARTE PARA PODER PUBLICAR MENSAJES! | TENEMOS CANAL OFICIAL DE TELEGRAM: t.me/unity3dspain

Parar la Ruta del enemigo

Iniciado por modding, Enero 03, 2016, 08:32:28 PM

Tema anterior - Siguiente tema
Enero 03, 2016, 08:32:28 PM Ultima modificación: Enero 01, 1970, 01:00:00 AM por modding
Hola, estoy haciendo un nivel en el que quiero el el enemigo siga una ruta, pero que en mitad de la rutina si detecta al jugador para esa rutina y vaya a por el.Ahora tengo el siguiente C# Script que lo que hace es únicamente la ruta, pero no se como añadirle que la ver al jugador la pare y le persiga. 
using UnityEngine;
    using System.Collections;


    public class Patrol : MonoBehaviour {

        public Transform[] points;
        private int destPoint = 0;
        private NavMeshAgent agent;


        void Start () {
            agent = GetComponent<NavMeshAgent>();

            // Disabling auto-braking allows for continuous movement
            // between points (ie, the agent doesn't slow down as it
            // approaches a destination point).
            agent.autoBraking = false;

            GotoNextPoint();
        }


        void GotoNextPoint() {
            // Returns if no points have been set up
            if (points.Length == 0)
                return;

            // Set the agent to go to the currently selected destination.
            agent.destination = points[destPoint].position;

            // Choose the next point in the array as the destination,
            // cycling to the start if necessary.
            destPoint = (destPoint + 1) % points.Length;
        }


        void Update () {
            // Choose the next destination point when the agent gets
            // close to the current one.
            if (agent.remainingDistance < 0.5f)
                GotoNextPoint();
        }
    }
Un Saludo y muchas gracias!

Busca informacion sobre "maquina de estados". Un saludo y suerte

Etiquetas: