예제 #1
0
        IEnumerator SpawnRandomEnemies()
        {
            while (true)
            {
                if (!(numberOfEnemiesSpawned >= 10))
                {
                    for (int i = 0; i < m_NumberOfSpawns; i++)
                    {
                        int     typeOfEnemyToSpawn = Random.Range(0, m_EnemyTypes.Length);
                        Vector2 positionToSpawn    = new Vector2(Random.Range(-m_SquareDistanceToSpawnIn, m_SquareDistanceToSpawnIn), Random.Range(-m_SquareDistanceToSpawnIn, m_SquareDistanceToSpawnIn));
                        Mobs    mobSpawned         = Instantiate(m_EnemyTypes[typeOfEnemyToSpawn], new Vector2(transform.position.x, transform.position.y) + positionToSpawn, Quaternion.Euler(0, 0, 0), enemyArray.transform);
                        mobsSpawned.Add(mobSpawned);
                        mobSpawned.gameObject.name = m_EnemyTypes[typeOfEnemyToSpawn].gameObject.name;
                        numberOfEnemiesSpawned++;
                    }
                }

                yield return(new WaitForSeconds(10));
            }
        }
예제 #2
0
        IEnumerator SpawnRandomEnemies()
        {
            while (true)
            {
                numberOfSpawns = 1;
                //  Debug.Log("Number of spawns: " + numberOfSpawns);
                int typeOfEnemyToSpawn = Random.Range(0, m_EnemyTypes.Length - 1);
                //  Debug.Log("Type of enemy to spawn: " + numberOfSpawns);
                for (int i = 0; i < numberOfSpawns; i++)
                {
                    Vector2 playerPos = m_Players[Random.Range(0, MenuData.m_playerNumber - 1)].m_hero.transform.position;
                    //   Debug.Log("PlayerPosition: " + numberOfSpawns);
                    Vector2 plusPosition;
                    plusPosition.x = Random.Range(0.0f, 1.0f) > 0.5 ? Random.Range(6.0f, 10.0f) : Random.Range(-6.0f, -10.0f);
                    plusPosition.y = Random.Range(0.0f, 1.0f) > 0.5 ? Random.Range(6.0f, 10.0f) : Random.Range(-6.0f, -10.0f);
                    Mobs mobSpawned = Instantiate(m_EnemyTypes[numberOfSpawns], playerPos + plusPosition, Quaternion.Euler(0, 0, 0), this.transform);
                    mobSpawned.gameObject.name = m_EnemyTypes[numberOfSpawns].gameObject.name;
                }


                yield return(new WaitForSeconds(10));
            }
        }