- Home /
Question by
Optiknights · Jun 01, 2014 at 05:47 PM ·
c#animationanimatoranimator controller
A better way to trigger animations.
Hi, I am looking at setting the same animation in x different positions using x different triggers. These triggers are GUI buttons that increase each "ButtonxState" by 1 which triggers the animation. This seams very inefficient to me and has already slowed down the program, what is a better way to do this (perhaps by instantiating?) Below is an example of the code:
public static int Button1State;
public static int Button2State;
.....
public static int Button(x-1)State;
public static int ButtonxState;
void Update(){
anim.SetInteger ("Button1State", Button1State);
anim.SetInteger ("Button2State", Button2State);
anim.SetInteger ("Button3State", Button3State);
.....
anim.SetInteger ("Button5State", Button(x-2)State);
anim.SetInteger ("Button6State", Button(x-1)State);
anim.SetInteger ("Button7State", ButtonxState);
}
Thank you!
Comment
Why are you setting every button state every frame in the Update loop? Presumeably you only need to call SetInteger to change the animator state when one of the buttons actually changes state?