- Home /
How do I transition between different animations?
I'm creating an FPS melee combat system (in which both arms are visible). I have created two attack animations along with an idle animation. The idle animation is specific to the left arm, therefore the right arm does not move during the idle animation. However, during the attack animations both arms move simultaneously. I have created a C# script that will play the animations when a certain key is pressed,but I came across a problem. In the beginning of the game the idle animation is playing on the left arm (like it's supposed to), however, when I play the attack animation on the right arm, the left arm stops playing the idle animation all together. I have been trying different ways to fix this but nothing seems to work. Is there a way that can cross fade between the animations? PLEASE HELP
here is the script I created :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ArmAnims : MonoBehaviour {
void Start ()
{
GetComponent<Animation>().Play("Idle_Left_Arm");
}
void Attack1()
{
GetComponent<Animation>().Play("Attack1_Right_Arm");
}
void Attack2()
{
GetComponent<Animation>().Play("Attack2_Right_Arm");
}
void Update()
{
if (Input.GetButtonDown("Fire1"))
{
Attack1();
}
if (Input.GetButtonDown("Fire2"))
{
Attack2();
}
}
}
Answer by tMahon · Jun 12, 2017 at 06:41 AM
Use the transitions tool in the Animator state machine. When you get input from the player in code change a Bool in your Animator component like isAttacking1, and set a transition to Attack1 with the condition isAttacking1 = true in the editor. If you need to do more from there you can attach a script to the State object and access OnStateEnter() and OnStateExit().
The Animator Bools are setup as Parameters in the Animator window
Answer by MadDevil · Jun 12, 2017 at 06:43 AM
Rather then using the script to change between 2 animation, try making and animation controller and assigning necessary value to have the transition between the 2 animations.
https://unity3d.com/learn/tutorials/topics/animation/animator-controller
check out the above link to see how to use the animation controller.
Your answer
![](https://koobas.hobune.stream/wayback/20220612123823im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Animations interupting Aim-Script 0 Answers
trying to link an aniamtion in one script to a action in another 0 Answers
Error CS0103, The name GetComponet does not exist in the current context. 1 Answer
Is there a new retargetting system for the animation in 5.5? 1 Answer
How can I use IK with AnimationClipPlayable or AnimationMixerPlayable? 1 Answer