- Home /
I want to sync my animations with eachother via Animator.SetTrigger
So I have my player object with it's own walking, attacking, and idle animations. I want to be able to equip a bunch of different weapons and armor onto my player and to swap them out with ease. I created prefab for the armor with it's own corresponding walking/attacking/idle animations AND corresponding mecanim or state machine or whatever you call it...what I'm trying to say is that the armor's animation clips, frames, parameters, ect all totally line up with the player's animations.
I then created an UnitAnimation script. This script loads up whatever armor prefab I decide to call, it attaches it to the Player as a child object, then collects the Player and the armor's Animators so that I can call them at the same time within this script. For example, if the player is attacking, I call UnitAnimation.AttackAnimation():
public void AttackAnimation(){
for(i=0;i<animators.Length;i++){
animator[i].SetTrigger("isAttacking");
}
}
This sets off the attacking animation in the player, armor, weapon, ect...then problem is, as you might guess from the above function, is that the for-loop has to call each Trigger one at a time. This seems to result in my animations being out of sync...so I my question is, how can I sync on my animations in this way?
I should note that this DOES work for my walking animation function:
public void WalkingAnimation(){
for(i=0;i<animators.Length;i++){
animator[i].SetBool("isWalking");
}
}
Might it have something to do with bools vs. triggers?
How about using the same animator for multiple meshes, wouldn't that be an option?
EDIT: otherwise maybe like this?
void Update()
{
if(startSyncAnim)
{
Animator1.Play(myfirstanimstate,-1, 0);
Animator2.Play(mysecondanimstate,-1, 0);
Animator3.Play(mythridanimstate,-1, 0);
}
}
found here