- Home /
Question by
Catlinman · Oct 28, 2012 at 03:50 PM ·
transformvector3colorvector3.distance
Ambientlight by distance
Is there a way to make the ambientlight change its color from a to b depending on the players distance to an object? I already have the code for detecting the distance but I don't know how to fade the color from one to another.
var Color1 : Color;
var Color2 : Color;
function Update(){
var distancePosition : Vector3;
distancePosition = transform.position;
var distance = Vector3.Distance(distancePosition,target.position);
//Code for the change from color1 to color2
}
Comment
open Unity,
open your project, open your scene,
click on the light in heirarchy
look at the inspector
notice the Light component
at the top right of the component. there is a small Book icon.
click it
The documentation will open at "Light"
Look at the top right. it says "Switch to scripting"
Click that.
You will immediately see what you need
Best Answer
Answer by farooqaaa · Oct 28, 2012 at 04:10 PM
Use Color.Lerp.
Color1 = Color.Lerp(Color1, Color2, 0.1f);
Your answer
![](https://koobas.hobune.stream/wayback/20220613083009im_/https://answers.unity.com/themes/thub/images/avi.jpg)