Skip to content

Instantly share code, notes, and snippets.

@openroomxyz
Created April 21, 2020 12:26
Show Gist options
  • Select an option

  • Save openroomxyz/263bddba8e2dc1c279e6002906b715d0 to your computer and use it in GitHub Desktop.

Select an option

Save openroomxyz/263bddba8e2dc1c279e6002906b715d0 to your computer and use it in GitHub Desktop.
Unity : How can we generate material in code?
Vector3 pos = new Vector3(x, y, z);
GameObject cube = GameObject.Instantiate(block, pos, Quaternion.identity);
cube.GetComponent<Renderer>().material = new Material(Shader.Find("Standard"));
cube.GetComponent<Renderer>().material.color = Random.ColorHSV();
cube.name = x + "_" + y + "_" + z;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment