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
Post a Comment