Beispiel #1
0
        private void SpawnSectionInteractables(Vector2[] columnPositions, Vector2[] wallPositions)
        {
            int scorePointCount = Mathf.Min(Random.Range(0, Mathf.FloorToInt(columnPositions.Length * template.MaxScorePointFrequency)), MapController.Singleton.ScorePointsAvailableToSpawn);
            int powerUpCount    = Random.Range(0, template.MaxPowerUpCount + 1);

            scorePoints = new ScorePoint[scorePointCount];

            // Make a list of all the available columnPosition indexes:
            List <int> indexes         = Enumerable.Range(0, columnPositions.Length).ToList();
            int        indexesToRemove = Mathf.Min(columnPositions.Length - scorePointCount - powerUpCount, indexes.Count);

            // Randomly remove those that will not be selected:
            for (int i = 0; i < indexesToRemove; i++)
            {
                indexes.RemoveAt(Random.Range(0, indexes.Count));
            }

            // Assign positions to the unpooled score points:
            for (int i = 0; i < scorePointCount; i++)
            {
                scorePoints[i] = MapController.Singleton.GetScorePoint();
                scorePoints[i].transform.position = (Vector2)transform.position + columnPositions[indexes[i]] + new Vector2(0f, Random.Range(wallPositions[indexes[i] * 2 + 1].y / 2f, wallPositions[indexes[i] * 2].y / 2f));
            }

            // Assign positions to the unpooled power ups:
            for (int i = scorePointCount; i < scorePointCount + powerUpCount; i++)
            {
                PowerUp powerUp = powerUpPool.GetPool(Random.value)?.GetItem() ?? null;

                if (powerUp != null)
                {
                    powerUp.transform.position = (Vector2)transform.position + columnPositions[indexes[i]];
                }
            }
        }