コード例 #1
0
        private void GenerateAsteroid()
        {
            var asteroidTemplateEntity = asteroidsPool.TemplatePrefab.GetComponent <IAsteroidEntity>();
            var verifyPosition         = false;
            var attempts   = 0;
            var randomPosX = 0f;
            var randomPosZ = 0f;

            while (!verifyPosition && attempts < 3)
            {
                randomPosX = Random.Range(asteroidSpawnArea.min.x + asteroidTemplateEntity.AsteroidSize.x, asteroidSpawnArea.max.x - asteroidTemplateEntity.AsteroidSize.x);
                randomPosZ = Random.Range(asteroidSpawnArea.min.z + asteroidTemplateEntity.AsteroidSize.z, asteroidSpawnArea.max.z - asteroidTemplateEntity.AsteroidSize.z);
                var count = Physics.OverlapBoxNonAlloc(new Vector3(randomPosX, asteroidSpawnArea.center.y, randomPosZ), asteroidTemplateEntity.AsteroidSize, overlapTest, asteroidsPool.TemplatePrefab.transform.rotation);
                if (count == 0)
                {
                    verifyPosition = true;
                }
                attempts++;
            }
            if (verifyPosition)
            {
                var asteroidGameObject = asteroidsPool.TakeFromPool(new Vector3(randomPosX, asteroidSpawnArea.center.y, randomPosZ), Quaternion.identity);
                var asteroidEntity     = asteroidGameObject.GetComponent <Asteroid.AsteroidEntity>();
                asteroidEntity.SetLevelBounds(levelEntity.LevelBounds);
                asteroidEntity.SetHP(defaultAsteroidsHP);
                leftAmountOfAsteroidsInScene++;
                leftAmountOfAsteroidsToGenerate--;
            }
        }
コード例 #2
0
 private void Fire()
 {
     var missileGameObject = missilePoolTemplate.TakeFromPool(missileSpawnPoint.position, missilePoolTemplate.TemplatePrefab.transform.rotation);
 }