Пример #1
0
    private Queue <SpawnZone> GetEnemiesSpawnZoneAndSetCurrentSpawnZone()
    {
        GameObject[] enemiesSpawnZones = GameObject.FindGameObjectsWithTag("EnemySpawn");
        if (enemiesSpawnZones.Length == 0)
        {
            Debug.Log("No enemySpawnZone");
            return(null);
        }
        System.Array.Sort(enemiesSpawnZones, CompareObNames);
        Queue <SpawnZone> queue = new Queue <SpawnZone>(enemiesSpawnZones.Length);

        // For each spawn zone : get the beginning and the ending of the zone, put it in an SpawnZone object and add it to the queue
        foreach (GameObject EnemySpawnZone in enemiesSpawnZones)
        {
            SpawnZone spawnZone         = (SpawnZone)SpawnZone.CreateInstance("SpawnZone");
            Vector3   beginningPosition = EnemySpawnZone.transform.localPosition;
            spawnZone.beginning = new Vector2(beginningPosition.x, beginningPosition.y);
            Vector3 zoneDimensions = EnemySpawnZone.transform.localScale;
            spawnZone.ending = new Vector2(beginningPosition.x + zoneDimensions.x, beginningPosition.y + zoneDimensions.y);
            queue.Enqueue(spawnZone);
        }

        currentSpawnZone = queue.Dequeue();
        return(queue);
    }