- Home /
Can't Switch Between Legacy Animations
I have 2 animations for an FPS arm/gun. One for hipfire and one for aiming down sights. The problem is it only plays the hipfire animation even when aiming down sights. I'm using a simple javascript in Unity 5. Is there something I'm missing?
The "Pistol001Shot" is the hipfire and the "Pistol001ShotAim" is the aim down sights.
var gunsound : AudioSource = GetComponent.<AudioSource>();
function Update ()
{
if (Input.GetButtonDown("Fire1"))
{
if (Input.GetButtonDown("Fire2"))
{
gunsound.Play();
GetComponent.<Animation>().Play("Pistol001ShotAim");
}
else if (!Input.GetButtonDown("Fire2"))
{
gunsound.Play();
GetComponent.<Animation>().Play("Pistol001Shot");
}
}
}
Answer by Immanuel-Scholz · Apr 19, 2016 at 07:39 AM
Input.GetButtonDown returns true only in the frame that the button has been pressed down.
This means, to get into the branch that plays Pistol001ShotAim, you have to simultanously press Fire1 and Fire2 in the exact same frame. Not very likely.
You probably want to test for Input.GetButton("Fire2")
in line 7 and 12 (which returns true as long as the button is held down - not only in the frame when its pressed).
Your answer

Follow this Question
Related Questions
How to control speed of animation on Unity by a .txt file? 1 Answer
Animation doesn't work 1 Answer
About mecanim and changing animations, there must be more clever way of doing this. 0 Answers
how to manage fbx files animation (blender) in unity using favascript 0 Answers
How do I make an aim down sight animation that can be used with mecanim? 2 Answers