- Home /
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
Answer by casperskyly · Apr 27, 2013 at 11:04 AM
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;
}
}
Your answer
Follow this Question
Related Questions
Light switch trigger 3 Answers
A big problem with my script.. 2 Answers
Light - Dark / Rendering only part of an 0 Answers
On Click, destroy object and any colliding object with the same tag. 6 Answers
Showing text near object 1 Answer