Two Times Button - Looping

Hello!

I have a small problem with looping the if/else function.

I need to turn off/on the lights in my game, while pressing the Middle Mouse Button. So I created animation for my lights and simply play it with normal speed, when the lights are off, and with inverse speed, when they’re turning on.

I wrote a small code for twice pressing the Middle Mouse Button (the example of twice pressing code I found on this site), but everything works ONLY ONCE. I press the button - the lights are turned off, press it again - they are turned on. Press again - and nothing going on! So I think, maybe it is possible to loop the function?

Please, help me and sorry for my English.)

Here’s the code:

var LampsOn = 0;

for (var state : AnimationState in animation) 

{
    state.speed = 0.0;
}

function Update() {

       if (LampsOn == 0 && Input.GetMouseButtonDown(2))
{

for (var state : AnimationState in animation) 

{
    state.speed = 1.0;
};
    LampsOn = 1;
}

else if (LampsOn == 1 && Input.GetMouseButtonDown(2))
{
for (var state : AnimationState in animation) 
{
    state.speed = -2.0; 
};
    LampsOn = 0;
    }

}

Perhaps, the problem is linked with state.speed, because in all other cases the looping method, which I found in unity answers (see the link below) works great.