- Home /
AddMixingTransform not working
I have a 2D game in which I have a character which I animate using bone based animation, not a rig. My issue is that I have a "Idle" animation and an "attack" animation, and I want to play the attack animation without affecting the idle and viceversa. I already tried playing the attack animation in a different layer but this approach doesn't work because of the "weight" property in the layers system, In this case i get the attack animation playing but it doesn't fully play, only a part.
Fast forward through a lot of research i stumbled upon the AddMixingTransform method and it looks like what I need, but I can't get it to work. I used the same code as in the unity docs: https://docs.unity3d.com/ScriptReference/AnimationState.AddMixingTransform.html (They don't give a lot more info than this) And then i try to play my animation when clicking, but nothing happens. This is what my code looks like:
public class PlayerAttacks : MonoBehaviour {
public Animation anim;
public Transform right_arm;
void Start()
{
// Add mixing transform
anim["MeleeAttack"].AddMixingTransform(right_arm);
}
// Update is called once per frame
void Update () {
if(Input.GetMouseButtonDown(0)){
anim.Play("MeleeAttack");
}
}
}
I created a game object with an animation component, which had the animation (which i marked as legacy) im trying to trigger, then i attached this object and the transform to the script, I also tried giving the animation component to the same transform i want to animate but none of the two approaches work.
Could anyone with experience with this method provide some insight on how to do this?