I have 4 objects with 1 different color materials for each one and I need to control the emission intensity value of the each material through of a script.
I am trying this:
public float intensity = 0.3f;
finalTargets [currentId].GetComponent<Renderer>().material.SetColor ("_EmissionColor", Color * intensity);
But I am getting some errors:
I read some solutions about to change the color but I need only to change the emission value. Is it possible? If so, please, tell me how can I do this.
As far as I know that value isn’t a separate variable to change. It’s akin to the “V” or “value” slider in the HSVA mode in the color picker.
After your answer I have verified the color picker and I figured out this is not a “intensity” field but a “brightness” field. Is it possible to control this value by code? Maybe by multiplying the color by a brightness factor. If so, how can I do to check the material color of each object before multiply it by the factor? And if the color is not accurate (e.g. not totally blue)?
However, in this case I am changing the color but it’s not shining and when I change the brightness thought the inspector panel the color shines. Can I do it by code?
Unfortunately I don’t know any more detailed information about how emissive materials work in Unity.
Check out this resource if you haven’t:
It’s down for maintenance right now though, so check back later.
Try using “Mathf.LinearToGammaSpace(intensity)” on your intensity and see how that affects the end result. If you’re seeing it work via the inspector, there’s definitely a way to do it through code.
I have tried “Mathf.LinearToGammaSpace(intensity)” before and the result also affected only the material color but not its brightness. I will check the tutorial about the emissive materials. Its very interesting and I hope it helps me.
I changed “yourcolor” to Color.white and now I have a glow but it’s not colorful. As I don’t intend to use an accurate color (green/yellow/etc) I will use the same color that I defined in the emission color through the brightness value for each object.