예제 #1
0
    public void updateStates()
    {
        timeSinceAttack += Time.deltaTime;
        walkTowards();
        if (enemyPattern.GetLineOfSight() < enemyPattern.distanceFrom)
        {
            toIdleState();
        }

        if (enemyPattern.inChallenge == true)
        {
            toChallengeState();
        }
    }
    public void updateStates()
    {
        if (enemyPattern.inChallenge == false)
        {
            toIdleState();
        }

        float[] distances = new float[enemyPattern.target.Length];

        for (int i = 0; i < distances.Length; ++i)
        {
            distances[i] = Vector3.Distance(enemyPattern.transform.position, enemyPattern.target[i].transform.position);
        }

        float smallestDistance = 999;
        int   smallestIDx      = 0;

        for (int i = 0; i < distances.Length; ++i)
        {
            if (distances[i] < smallestDistance)
            {
                smallestDistance = distances[i];
                smallestIDx      = i;
            }
        }

        for (int i = 0; i < distances.Length; ++i)
        {
            if (distances[i] < enemyPattern.GetLineOfSight())
            {
                enemyPattern.navMeshAgent.SetDestination(enemyPattern.target[smallestIDx].transform.position);
            }
        }
    }
예제 #3
0
    private void playerInRange()
    {
        if (enemyPattern.endGame == true)
        {
            return;
        }
        else
        {
            for (int i = 0; i < enemyPattern.target.Length; ++i)
            {
                enemyPattern.distanceFrom = Vector3.Distance(enemyPattern.transform.position, enemyPattern.target[i].transform.position);

                if (enemyPattern.distanceFrom < enemyPattern.GetLineOfSight())
                {
                    toAttackState();
                }
                else
                {
                    if (enemyPattern.wayPoints.Length > currentDestination && enemyPattern.inChallenge == false)
                    {
                        if (Vector3.Distance(enemyPattern.transform.position, enemyPattern.wayPoints[currentDestination].transform.position) < 6)
                        {
                            newDestination(currentDestination);
                        }
                        enemyPattern.navMeshAgent.SetDestination(enemyPattern.wayPoints[currentDestination].transform.position);
                    }
                }
            }
        }
    }