How do I loop my light animation is javascript?

Hi guys, I have a trigger that when I collide with it my light is triggered and flashes. I tried using wrap mode loop but it still just plays once, my code is below, does anyone know why this doesn’t work?

var myLight : Light;

function Start() {
	myLight = GameObject.Find ("Alarm Light").GetComponent(Light);
	myLight.enabled = false;
}


function OnTriggerEnter (other : Collider)
{
    if (!AlarmSetOff)
    {
		myLight.enabled = !myLight.enabled;
		myLight.animation["LightFlash"].wrapMode = WrapMode.Loop;
    }
}

Just a question, is this alarm light just a spinning light/single object? If so, you don't even need an animation.

Alarm light is just the name of the light attached to the character that I want to flash. this script is also to do other thing like adding sound as well though :S hope this helps

"LightFlash" has to be attached to the object, and animated so that appears/stays and dissapears/flysOutOfBounds like you want it to. and loop that

the "LightFlash" animation is attatched to my light "Alarm Light" but it doesnt loop, how do I loop that

1 Answer

1

You should make a boolean and a Update function, it will loop automatically.

var alarmIsRunning : boolean = false;
var myLight : Light;
 
function Start() {
    myLight = GameObject.Find ("Alarm Light").GetComponent(Light);
    myLight.enabled = false;
}

function Update(){
  if (alarmIsRunning){
     myLight.animation.Play("LightFlash");
  }
}
 
function OnTriggerEnter (other : Collider)
{
    if (!AlarmSetOff)
    {
       myLight.enabled = !myLight.enabled;
       alarmIsRunning = !alarmIsRunning;
    }
}