コード例 #1
0
    // Start is called before the first frame update
    void Awake()
    {
        boxes = new List <GameObject>();
        float startPosX = -(lvlSize / 2f) * boxSize;
        float startPosY = -(lvlSize / 2f) * boxSize;

        for (int x = 0; x < lvlSize; x++)
        {
            for (int y = 0; y < lvlSize; y++)
            {
                GameObject   newBox      = Instantiate(paintBoxPrefab, new Vector2(startPosX + (x * boxSize), startPosY + (y * boxSize)), Quaternion.identity);
                float        rand        = Random.Range(0f, 1f);
                ColorHandler currHandler = newBox.GetComponent <ColorHandler>();
                if (rand < 0.5f)
                {
                    currHandler.SetGoalColor(color1);
                }
                else
                {
                    currHandler.SetGoalColor(color2);
                }
                boxes.Add(newBox);
            }
        }
    }