how would i make it so that i can add more than one light to this script? if not could you point me in the right direction please. thank you
var lightObject : Transform;
function OnTriggerEnter (other : Collider) {
lightObject.light.enabled = false;
}
2 Answers
2
public var lightObjects:Transform;
function OnTriggerEnter (other : Collider) {
for (var lightObject: Transform in lightObjects) {
lightObject.light.enabled = false;
}
}
you would use an array and a For Loop.
something like:
public GameObject [] lightObject;
void OnTriggerEnter (other : Collider)
{
for (int i = 0; i < lightObject.length; i++)
{
lightObject*.light.enabled = false;*
}
}
that will cycle through all the lights in your array and turn each off
i just gave that a go and get an error for unexpected token, any ideas, thank you
– ryisnelly@ryisnelly should work now.
– KellyThomasthat works perfect, thanks alot how would i make it activate just once? thank you
– ryisnellypublic var lightObjects:Transform[]; private var hasRunAlready = false; function OnTriggerEnter (other : Collider) { if (!hasRunAlready) { for (var lightObject: Transform in lightObjects) { lightObject.light.enabled = false; } hasRunAlready = true; } }
– KellyThomas