This code works for me, if I mimick it in a small use case that is:
using UnityEngine;
public class tmp : MonoBehaviour
{
[SerializeField]
Color c = Color.white;
[SerializeField]
float i = 0.25f;
void Start()
{
//Light light = GetComponent<Light>();
light.color = c;
light.intensity = i;
light.range = 3;
}
}
I changed the color in the inspector to various things and it all turned out correctly.
Two things I would like to tell you
Light is multiplicative, if you have a light source that is 100% blue (so new Color(0,0,255)
and put it in a scene that has the default material, everything is blue. But if you create a new material and make the color red (255,0,0) everything will be black. This is because blue * red = black, red contains no blue so blue light only shows the blue part, which is zero. (0255, 00, 255*0) = (0,0,0)
So in short: I think your light color mismatches with your material color making some objects appear correct and other over-bright.
Tips: Make your light look right when the light is white, desaturate your textures so colored lights can influence the world with whaterver color they have and possibly desaturate the lights either way. Colors look bright in comparison to their surrounding, if something is only a little red in a grey world it will still look very red so don’t worry about your world becoming too flat - as long as the contrast is right.
Additionally (if you have pro) you can solve the boring-ness of colors by upgrading the saturation with a post effect.
Another, totally unrelated thing, I’d also like to recommend you to use a public or serialized field to put the light in like so (this is not related to your question at all but I just noticed it in your code):
public class MyClass : MonoBehaviour
{
[SerializeField]
Light spellLight;
/*
void Start() etcetera
*/
}
So you can use drag and drop in the editor instead of using gameobject.find → which will give problems when you have more than 1 object with this name, possibly one having no light source at all etcetera. Also it is faster on startup and gives better error messages (null reference on the specific property so you know the object that was in there was deleted or has not been filled in etcetera).
@eran0201 That didn't work. Intensity already changed as you can see in the code. Any other ideas?
– Party_Boy