Skip to content

Instantly share code, notes, and snippets.

Created August 29, 2022 06:39
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Setting Random Material color to game object inside unity editor
var newObstacle = Instantiate(cube, new Vector3(i, 0, j), Quaternion.identity, transform);
Renderer obstacleRenderer = newObstacle.GetComponent<Renderer>();
Material mat = new Material(obstacleRenderer.sharedMaterial);
mat.color = GetRandomColor();
obstacleRenderer.sharedMaterial = mat;
public Color GetRandomColor()
var random = Random.Range(1, 10);
if(random<4) return;
else if(random<7) return;
else return;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment