Hey guys,
I am making a game with a big city and many dynamic lights.
To save performance I am making a script to disable and enable lights when you get in close proximity + no object is in the way.
I woud like it so that the script also only executes when the actual light is seen by the camera
So far I have this:
var fadeLights = 0.00;
function Update () {
distancevar = Vector3.Distance(transform.position, target.position);
var hit : RaycastHit;
if(Physics.Linecast(transform.position, target.position, hit)){
if(hit.collider.gameObject.tag == "PLAYER" && distancevar < range && Tod.lightsOnOff == 1){
this.light.enabled = true;
if(this.light.intensity < 1){
this.light.intensity += 10*Time.deltaTime;
}
}
else{
if(this.light.intensity <= 0){
this.light.enabled = false;
}
if(this.light.intensity > 0){
this.light.intensity -= 10*Time.deltaTime;
}
}
}
}
Do you guys have an idea what I need to add to the first if statement to achieve this?
PS, I am quite new at unity so please if you can explain it fully.