1
\$\begingroup\$

I have this code for creating a light:

            GameObject lightGameObject = new GameObject ("Light1");
            lightGameObject.AddComponent (typeof(Light));
            lightGameObject.light.color = Color.white;

            lightGameObject.light.intensity = 0.5f;

I want to change the light's intensity to 0.5f but when I run the game, the intensity's still at 1.

\$\endgroup\$
1
\$\begingroup\$

That is indeed the correct way to set the light's intensity. It's likely you have an error elsewhere in your code or you're not interpreting the results of the light intensity correctly. For example you might be creating multiple lights on accident and their combined intensities might look brighter than you're expecting.

Check the object hierarchy to make sure you don't have multiple lights. Also use the inspector to determine the actual intensity of the light you have created.

Finally you can attach the debugger and inspect to properties of the light after creation to ensure they're being modified as you expect and that the value is not being modified elsewhere.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.