I’m trying to make a wall in c#. I want to set differents colors for each cube, but when i run it, all cubes are white. here is my code:
public class Wall : MonoBehaviour
{
// Use this for initialization
void Awake()
{
for (int i = 0; i < 5; i++)
for (int j = 0; j < 5; j++)
{
GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.transform.position = new Vector3(i, j, 0);
cube.renderer.material.color = getRandColor();
}
}
private Color getRandColor()
{
print(Random.value);
int r = (int)(Random.value * 255);
int g = (int)(Random.value * 255);
int b = (int)(Random.value * 255);
print(r + "---" + g + "---" + b + "---");
return new Color(r, g, b);
}
// Update is called once per frame
void Update()
{
}
}