Hey guys it’s me again with another trigger question sorry for spamming the forum but you guys have been really helpful and I really need this for my game. Anyway, I have a trigger set up, works fine. but I just need to add something that will turn off all lights when I enter the trigger. Any ideas?
Here’s the script:
private var soundPlayed : boolean = false;
var Audio : AudioClip;
var volume: float = 10.45;
var Light :
function OnTriggerEnter(col : Collider){ //Play Sound if player enters trigger
if (!soundPlayed && Audio) { // but only if it has not played before
AudioSource.PlayClipAtPoint(Audio, transform.position, 10.4);
soundPlayed = true; // sound will not play anymore
}
}
The main thing you need to do is have a reference to the light (or lights) you need to access and then “diable” them by turning enabled to false. Here is your code with the added lines for accessing a light by dragging it to the script in the inspector and then disabling it when the trigger is entered.
Enable/Disable is the same as clicking the checkbox next to the top of the light component.
private var soundPlayed : boolean = false;
var audio : AudioClip; // Note change of capitalization of var name
var volume: float = 10.45;
var light : Light // Note change of capitalization of var name
function OnTriggerEnter(col : Collider){
//Play Sound if player enters trigger
if (!soundPlayed && audio) {
// but only if it has not played before
AudioSource.PlayClipAtPoint(audio, transform.position, 10.4);
soundPlayed = true;
// sound will not play anymore
}
light.enabled = false;
}
You could also use:
var lights : Light []; // which will use an array and then use:
for (var light : Light in lights) {
light.enabled = false;
}
ahh, it’s not working for me. Here is the script again. There were some errors in the last.
private var soundPlayed :
boolean = false;
var Laugh : AudioClip;
var volume: float = 10.45;
var LightOff : AudioClip;
var light : Light;
function OnTriggerEnter(col : Collider){ //Play Sound if player enters trigger
if (!soundPlayed && Laugh) { // but only if it has not played before
AudioSource.PlayClipAtPoint(Laugh, transform.position, 10.4);
soundPlayed = true; // sound will not play anymore
}
GetComponent.Light.enabled = false;
}