Applying materials to Unity objects that you dynamically created in a C# script

I had a problem with these materials being pink. Turns out, you just have to put the material inside of a folder called Resources, and then the color is applied. 

Material fluidMaterial = Resources.Load("FluidTest", typeof(Material)) as Material;

sphere.GetComponent<MeshRenderer>().material = fluidMaterial;

sphere.GetComponent<Renderer>().material = fluidMaterial;

I actually don't remember if it's MeshRenderer or just Renderer so I have both but w/e. 

Comments

Popular posts from this blog

Unleashing my inner Disney Princess ✩₊˚.⋆☾⋆⁺₊✧ at the 2024 Disney Princesses Half Marathon

The 20-something types of Computer Science majors

The Evenstar