Beispiel #1
0
    IEnumerator Move()
    {
        Vector3 point       = RandomPointOnNavMesh();
        float   waitTime    = 3f;
        float   elapsedTime = 0f;

        // Move to a random location
        while (currentState == State.Move)
        {
            if (!health.isAlive())
            {
                StopAllCoroutines();
                yield return(null);
            }

            actions.Move(point);
            elapsedTime += Time.deltaTime;

            // Select a new destination
            if (elapsedTime >= waitTime)
            {
                elapsedTime = 0f;
                point       = RandomPointOnNavMesh();
            }

            // If can fire, then fire
            if (Time.time >= nextFire)
            {
                ChangeState(State.Attack);
                yield break;
            }

            yield return(null);
        }
    }