Hi,
I am very bad with math and quite new to Unity, so I hope someone can help me out.
In my scene I have a simple First Person Controller and a point light. There’s a script attached to the point light which calculates the distance between the player and the light. Based on this data I want the intensity of the light to change. Meaning that the light must be brighter when the player gets closer, and less bright when the player is further away.
I also have a variable maxIntensity which is set to 3.0 so the light doesn’t get too bright. Is there a simple way I can use to get the desired result? Also, this may only work when the distance is less than 100.
Script:
var Target : Transform;
var distance : float;
var maxIntensity : float = 3.0;
function Update() {
distance = Mathf.Round(Vector3.Distance(gameObject.transform.position, Target.transform.position));
if(distance < 100) {
light.intensity = ...
}
}