Exemplo n.º 1
0
        IEnumerator WaitForDestinationReached()
        {
            while (!ai.reachedEndOfPath)
            {
                yield return(null);
            }

            ai.canMove            = false;
            CurrentMovementTarget = null;
            if (ReachedDestination != null)
            {
                ReachedDestination.Invoke();
            }
        }
Exemplo n.º 2
0
        public void MoveTo(MovementTarget movementTarget)
        {
            if (movementTarget == CurrentMovementTarget)
            {
                return;
            }

            CurrentMovementTarget = movementTarget;
            ai.destination        = movementTarget.transform.position;
            if (ChangedDestination != null)
            {
                ChangedDestination.Invoke();
            }
            ai.SearchPath();
            StartCoroutine(WaitForPathComplete());
        }
Exemplo n.º 3
0
        IEnumerator WaitForPathComplete()
        {
            while (ai.pathPending)
            {
                yield return(null);
            }

            // Проверяем, не стоит ли ИИ на клетке, по которой щёлкнули.
            List <GraphNode> path    = seeker.GetCurrentPath().path;
            Vector3          pathEnd = (Vector3)path[path.Count - 1].position;

            if (Vector3.Distance(ai.position, pathEnd) > ai.endReachedDistance)
            {
                // Если не стоит, то движемся.
                ai.canMove = true;
            }
            else
            {
                // Если стоит, то удаляем путь и не движемся.
                ai.enabled            = false;
                ai.enabled            = true;
                CurrentMovementTarget = null;
                if (WentToDestination != null)
                {
                    WentToDestination.Invoke();
                }
                if (ReachedDestination != null)
                {
                    ReachedDestination.Invoke();
                }
                yield break;
            }

            if (WentToDestination != null)
            {
                WentToDestination.Invoke();
            }
            StartCoroutine(WaitForDestinationReached());
        }