Hello everyone! When I create an object within a game I want it to change color to green. The scripting reference suggests using renderer.material.color, which doesn’t seem to work - the color doesn’t change. The compiler didn’t find any errors and the rest of the script works perfectly. Does any of you know what the problem might be? Or is there a better way to change object’s color?
Projection = (GameObject)Instantiate(BuildingPrefab, hit.point, Quaternion.identity);
Projection.renderer.material = new Material (Shader.Find(" Glossy"));
Projection.renderer.material.color = Color.green;
EDIT: Fixed it myself. The problem was that my prefab had more than one renderer attached to it.
where did you get the glossy shader from? (it's not a unity default) perhaps the shader doesnt have a color parameter to change
– sparkzbarcaAh, stupid me. That explains it - I found someone's post describing a similar problem and just copied the shader's name thinking it's default. I'll try to change it to something else now and say whether it helps. Thanks!
– DrSlashSame problem when using "Specular" or "Diffuse" shaders.
– DrSlashyou want to use i think shader "material" then change color specular and diffuse shaders dont have color either I dont believe. (they affect how the object reacts to light but not the color of the object I THINK) the material if you have an object open in inspector and you mouse of the materials and you click on it and you select a material you select material and you have have a shader with a color option. if you select default diffuse for example you dont get that.
– sparkzbarcabasically all the specular shader does is wash out an object at the point at whcih a light hits with super bright (normally white, though based on light color) light. it's that blinding white spot on metal hit by light. then diffuse is basically light hitting the object from a light source but lighting up areas other than the point of impact. the whole rest of the object being lit indirectly. That though doesnt affect the color. Color comes from the light, that just affects basically the brightness level per pixel of the object. Not the color of the pixels.
– sparkzbarca