- Home /
Animation play on multiple object
Something wrong in my animation play on multiple object
i 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.
Answer by clunk47 · Oct 05, 2013 at 03:18 AM
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...
}
}
Just to explain to @cocleu The reason you must do this, is because with program$$anonymous$$g, you can ignore {} wraps if your conditional statement only has one line of code inside of its scope
Your answer
![](https://koobas.hobune.stream/wayback/20220613115340im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Can I make animations snap to a frame? 1 Answer
Select frame for Animation 1 Answer
Call a function dependent on frame of animation? 2 Answers
Animation won't complete unless button is held 1 Answer
Animation doesn't fully play. 1 Answer