Animation play on multiple object

Something wrong in my animation play on multiple object

Hi everybody,

I have 9 panels, each panel has 30frames animation and start every 10frames (1st panel start at frame 0, 2nd panel start at frame 10…to 9th panel…) and each animation is set wrapmode to play once (it will look like a backdrop on stage).

here is my code:

var panel1 : GameObject;
var panel2 : GameObject;
var panel3 : GameObject;
var panel4 : GameObject;
var panel5 : GameObject;
var panel6 : GameObject;
var panel7 : GameObject;
var panel8 : GameObject;
var panel9 : GameObject;

function Update (){
if (Input.GetMouseButtonDown(0))
panel1.animation.Play("panel1");
panel2.animation.Play("panel2");
panel3.animation.Play("panel3");
panel4.animation.Play("panel4");
panel5.animation.Play("panel5");
panel6.animation.Play("panel6");
panel7.animation.Play("panel7");
panel8.animation.Play("panel8");
panel9.animation.Play("panel9");  
}

After insert above script, 9 panels play animation when game start (not left click yet) and look like a mess.

when i deactive above script and set every animation to “start automatically” it’s work fine.

But i want them play when i click left mouse button.

Thanks.

You are only firing panel1 animation. You need to open and close your if statement with brackets, just like your Update function.

function Update()
{
    if(your condition)
    {
        Do your thing.
        Do your other things.
        panel3, panel4, panel5, etc...
    }
}