// Spawn a blocker at the position private void SpawnBlocker(int currZ, int colorMax) { Blocker nb = Instantiate(blocker, new Vector3(0, 0, currZ), Quaternion.identity); // TODO: give material (unknown TODO) int m = Random.Range(0, materials.Length); if (m == colorIndex) // The color is a consecutive color { ++consecutiveColor; if (consecutiveColor > colorMax) // The limit for consecutive color has been reached { ++m; if (m >= materials.Length) // Array wrap around { m = 0; } consecutiveColor = 1; // New blocker is first instance of new consecutive color count } } colorIndex = m; nb.gameObject.GetComponent <Renderer>().material = materials[m]; nb.SetColor(materials[m].GetColor("_BaseColor")); }