Пример #1
0
    void SpawnEnemies(int total, BoardManager.Locations location)
    {
        //enemies.Clear();

        for (int i = 0; i < total; i++)
        {
            SpawnEnemy(location);
        }

        switch (location)
        {
        case BoardManager.Locations.Cockpit:
            audio.PlayOneShot(enemySpawnVent, 0.7F);
            break;

        case BoardManager.Locations.Oxygen:
            audio.PlayOneShot(enemySpawnPot, 0.7F);
            break;

        case BoardManager.Locations.Items:
            audio.PlayOneShot(enemySpawnGlass, 0.7F);
            break;

        case BoardManager.Locations.Health:
            audio.PlayOneShot(enemySpawnVent, 0.7F);
            break;

        default:
            audio.PlayOneShot(enemySpawnVent, 0.7F);
            break;
        }
    }
Пример #2
0
    void SpawnEnemy(BoardManager.Locations location)
    {
        Vector3 position;

        float minX = 0f;
        float maxX = 0f;
        float minY = 0f;
        float maxY = 0f;

        switch (location)
        {
        case BoardManager.Locations.Cockpit:
            Debug.Log("Cockpit");
            minX = 1;
            maxX = 13;
            minY = 1;
            maxY = 12;
            break;

        case BoardManager.Locations.Oxygen:
            Debug.Log("Oxygen");
            minX = 16;
            maxX = 28;
            minY = 9;
            maxY = 19;
            break;

        case BoardManager.Locations.Items:
            Debug.Log("Items");
            minX = -14;
            maxX = -2;
            minY = 9;
            maxY = 19;
            break;

        case BoardManager.Locations.Health:
            Debug.Log("Health");
            minX = 0;
            maxX = 14;
            minY = 15;
            maxY = 28;
            break;

        default:
            // in case of a default, just go to the cockpit
            minX = 1;
            maxX = 13;
            minY = 1;
            maxY = 12;
            break;
        }

        position = new Vector3(Random.Range(minX, maxX), Random.Range(minY, maxY), 0f);
        Debug.Log("position: " + position + " location: " + location);
        Instantiate(enemy, position, Quaternion.identity);
    }
Пример #3
0
    // Select a target for the Enemy to attack
    void SelectTarget()
    {
        touchingStation = false;

        GameObject player = GameObject.FindGameObjectWithTag(Tags.PLAYER);

        // Figure out which room the enemy is currently in
        BoardManager.Locations enemyLocation = BoardManager.DetermineLocation(gameObject.transform.position);

        // Ensure there is a 20% chance that an enemy in the same room as a player will attack them
        if (Random.Range(0, 100) < 20 && enemyLocation == BoardManager.DetermineLocation(player.transform.position))
        {
            target = player;
            return;
        }

        // Head for the closest restoration station
        GameObject closestStation    = null;
        float      distanceToClosest = 5000f;

        GameObject[] stations = GameObject.FindGameObjectsWithTag(Tags.RESTORATION_STATION);

        // Calculate the closest Restoration Station
        foreach (GameObject obj in stations)
        {
            // Only take into account stations that are not health stations and that are in the same room as the enemy
            if (obj.name != RestorationStations.HEALTH_STATION && BoardManager.DetermineLocation(obj.transform.position) == enemyLocation && obj != null)
            {
                Transform station  = obj.transform;
                float     distance = Vector2.Distance(gameObject.transform.position, station.position);

                if (distance < distanceToClosest)
                {
                    distanceToClosest = distance;
                    closestStation    = obj;
                }
            }
        }

        if (closestStation != null)
        {
            target = closestStation;
        }
        else
        {
            target = GameObject.FindGameObjectWithTag(Tags.PLAYER);
        }
    }