Esempio n. 1
0
        public void findTarget(List <Enemy> enemies)
        {
            if (enemies.Count == 0)
            {
                return;
            }
            List <DistanceEnemy> distancias = new List <DistanceEnemy>();

            for (int i = 0; i < enemies.Count; i++)
            {
                DistanceEnemy dE = new DistanceEnemy(i, Calculus.distanceFromPoints(centerRealPosition, enemies[i].CenterPosition));
                distancias.Add(dE);
            }

            distancias.Sort((d1, d2) => d1.distance.CompareTo(d2.distance));

            // Si la distancia al objetivo más cercano es menor de qje el rango entonces actualizar el enemigo
            // actual, si no asignar valor nulo
            currentEnemy = distancias[0].distance < range ? enemies[distancias[0].index] : null;

            if (currentEnemy == null)
            {
                return;
            }
        }
Esempio n. 2
0
    private void InstantiateEnemy(TEnemyTypes enemyType, TZones zone, int spawnID)
    {
        // Create variables
        MeleeEnemy    l_CurrentMeleeEnemy    = null;
        DistanceEnemy l_CurrentDistanceEnemy = null;

        // Depending on enemy type add in list and get enemy inactive
        switch (enemyType)
        {
        case TEnemyTypes.Teeth:
            l_CurrentMeleeEnemy = GameController.Instance.GetTeethEnemyInactive();
            m_MeleeEnemiesAliveList.Add(l_CurrentMeleeEnemy);
            break;

        case TEnemyTypes.Helicopter:
            l_CurrentDistanceEnemy = GameController.Instance.GetHelicotperEnemyInactive();
            M_DistanceEnemiesAliveList.Add(l_CurrentDistanceEnemy);
            break;

        case TEnemyTypes.Robot:
            l_CurrentMeleeEnemy = GameController.Instance.GetRobotEnemyInactive();
            m_MeleeEnemiesAliveList.Add(l_CurrentMeleeEnemy);
            break;
        }
        // If enemy is melee
        if (l_CurrentMeleeEnemy != null)
        {
            // ChangePosition depending on zone
            switch (zone)
            {
            case TZones.Military:
                l_CurrentMeleeEnemy.OnInit(m_MilitarySpawnPositions[spawnID].transform.position);
                l_CurrentMeleeEnemy.m_NavMeshAgent.enabled = true;
                l_CurrentMeleeEnemy.m_NavMeshAgent.Warp(m_MilitarySpawnPositions[spawnID].transform.position);
                break;

            case TZones.Twin1:
                l_CurrentMeleeEnemy.OnInit(m_MedievalSpawnPositions1[spawnID].transform.position);
                l_CurrentMeleeEnemy.m_NavMeshAgent.enabled = true;
                l_CurrentMeleeEnemy.m_NavMeshAgent.Warp(m_MedievalSpawnPositions1[spawnID].transform.position);
                break;

            case TZones.Twin2:
                l_CurrentMeleeEnemy.OnInit(m_MedievalSpawnPositions2[spawnID].transform.position);
                l_CurrentMeleeEnemy.m_NavMeshAgent.enabled = true;
                l_CurrentMeleeEnemy.m_NavMeshAgent.Warp(m_MedievalSpawnPositions2[spawnID].transform.position);
                break;

            case TZones.Student:
                l_CurrentMeleeEnemy.OnInit(m_StudentSpanwPositions[spawnID].transform.position);;
                l_CurrentMeleeEnemy.m_NavMeshAgent.enabled = true;
                l_CurrentMeleeEnemy.m_NavMeshAgent.Warp(m_StudentSpanwPositions[spawnID].transform.position);
                break;

            case TZones.Barbie:
                l_CurrentMeleeEnemy.OnInit(m_BarbieSpawnPositions[spawnID].transform.position);
                l_CurrentMeleeEnemy.m_NavMeshAgent.enabled = true;
                l_CurrentMeleeEnemy.m_NavMeshAgent.Warp(m_BarbieSpawnPositions[spawnID].transform.position);
                break;
            }
        }
        // If is distance enemy
        else
        {
            // ChangePosition depending on zone
            switch (zone)
            {
            case TZones.Military:
                l_CurrentDistanceEnemy.OnInit(m_MilitarySpawnPositions[spawnID].transform.position);
                l_CurrentDistanceEnemy.m_NavMeshAgent.enabled = true;
                l_CurrentDistanceEnemy.m_NavMeshAgent.Warp(m_MilitarySpawnPositions[spawnID].transform.position);
                break;

            case TZones.Twin1:
                l_CurrentDistanceEnemy.OnInit(m_MedievalSpawnPositions1[spawnID].transform.position);
                l_CurrentDistanceEnemy.m_NavMeshAgent.enabled = true;
                l_CurrentDistanceEnemy.m_NavMeshAgent.Warp(m_MedievalSpawnPositions1[spawnID].transform.position);
                break;

            case TZones.Twin2:
                l_CurrentDistanceEnemy.OnInit(m_MedievalSpawnPositions2[spawnID].transform.position);
                l_CurrentDistanceEnemy.m_NavMeshAgent.enabled = true;
                l_CurrentDistanceEnemy.m_NavMeshAgent.Warp(m_MedievalSpawnPositions2[spawnID].transform.position);
                break;

            case TZones.Student:
                l_CurrentDistanceEnemy.OnInit(m_StudentSpanwPositions[spawnID].transform.position);
                l_CurrentDistanceEnemy.m_NavMeshAgent.enabled = true;
                l_CurrentDistanceEnemy.m_NavMeshAgent.Warp(m_StudentSpanwPositions[spawnID].transform.position);
                break;

            case TZones.Barbie:
                l_CurrentDistanceEnemy.OnInit(m_BarbieSpawnPositions[spawnID].transform.position);
                l_CurrentDistanceEnemy.m_NavMeshAgent.enabled = true;
                l_CurrentDistanceEnemy.m_NavMeshAgent.Warp(m_BarbieSpawnPositions[spawnID].transform.position);
                break;
            }
        }
    }