예제 #1
0
    public void SpawnInCircle()
    {
        centerPos   = transform.position;
        colorsArray = new Color[numberOfPoints];
        circles     = new GameObject[numberOfPoints];
        gameManager.SetNumberOfBallsSpawned(numberOfPoints);

        for (int i = 0; i < numberOfPoints; i++)
        {
            float      j           = (i * 1.0f) / numberOfPoints;
            float      angle       = j * Mathf.PI * 2f;
            var        x           = Mathf.Sin(angle) * 2f;
            var        y           = Mathf.Cos(angle) * 2f;
            var        pos         = new Vector3(x, y, 0) + parentCircle.transform.position;
            GameObject colorCircle = (GameObject)Instantiate(gamePrefab, pos, Quaternion.identity);
            circles[i] = colorCircle;
            colorCircle.transform.SetParent(parentCircle.transform);
            Color _randomColor = GenerateRandomColor(i, 1.0f / (float)numberOfPoints);
            colorCircle.GetComponent <SpriteRenderer>().color = _randomColor;
            colorCircle.GetComponent <Light>().color          = _randomColor;
            colorsArray [i] = colorCircle.GetComponent <SpriteRenderer> ().color;
        }

        spawnController.AcquireColors(colorsArray);
    }