Dim lights while camera (player) comes closer to the light source
Hello!
I am very new in Unity, trying to solve a thing. How can I dim lights while the camera/player moving away from the light source? I need to study architectural dynamic lighting/sensors, it'd be great if you could help.
Thank you!
Answer by Commoble · Mar 06, 2017 at 01:09 AM
On a script on your light object, use Vector3.Distance() to get the distance between the light and the player's object, then use that to calculate what you want the light's intensity to be and set its intensity variable.
Thanks for the reply!
However, my coding knowledge is like.. zero. I can tell you the distance, it is 5m, but I really don't know how can I combine these two scripts. Would you help me out on that? I would greatly appreciate!
If you haven't read the unity manual's section on scripting, I suggest doing that, especially the bits on controlling gameobjects and components via scripts. For an even more basic introduction to C#, there's some good unity-oriented tutorials here.