Hi - I’ve written a script which fades the scene black when my player hits a trigger.
I’ve attached it to a certain collider - and the first time I play the game it works fine.
Every time after that however - the scene turns black when the player is set to active at a different collider to which this script is not attached - rather than when the player, after being set to active, hits a trigger later on, to which this script is attached.
Do you have any idea why this is?
var intensityBlack:float = 0;
private var IsBlack:boolean = false;
private var cLight:GameObject;
function Start() {
cLight = GameObject.Find("Lighting");
}
function OnTriggerEnter(other:Collider) {
if(other.tag == "Carl") {
IsBlack = true;
}
}
function Update() {
if(IsBlack) {
if(cLight.renderer.material.color.b != 0 ) {
cLight.renderer.material.color.a -=Time.deltaTime*intensityBlack;
if( cLight.renderer.material.color.a<=0)//set to black as the current fading is to white
cLight.renderer.material.color = Color(0,0,0,0);
}
else
cLight.renderer.material.color.a +=Time.deltaTime*intensityBlack;
}
}
Thanks in advance,
Laurien