- Home /
How to get different Animations when different button combos are pressed
I have a gun (Same project as my other questions) and I have aiming and shooting and all this kind of stuff. What I'm trying to do is when I press the left mouse it will play the shooting animation, but if I am aiming down the sight (which is achieved by holding the Right mouse button) I want it to play a different animation I made at the exact ADS coordinates. My attempts are not working. Here is my script:
if(Input.GetButtonDown("Fire2") && ("Fire1"))
{
GameObject.Find("Assault_Rifle").animation.Play("ADS Shoot");
}
if(Input.GetButtonDown("Fire1"))
{
GameObject.Find("Assault_Rifle").animation.Play("Shoot");
}
Answer by senad · Jul 18, 2012 at 09:40 AM
You should make the second if-statement an "else if". Otherwise it will always get entered after the first one, which you do not want.
So I guess that with your current code only the "Shoot" animation gets ever played?
I wrote this: if(Input.GetButtonDown("Fire2") && ("Fire1")) { GameObject.Find("Assault_Rifle").animation.Play("ADS Shoot"); } else if(Input.GetButtonDown("Fire1")) { GameObject.Find("Assault_Rifle").animation.Play("Shoot"); } and feel like its wrong. I don't have any compile errors, but the ADS Shoot anim doesn't play.
You still write ("Fire") without the Input.GetInputButton. $$anonymous$$aybe it is the reason.
Independently from this, you should check, if the first if-branch is entered at all. Put in a breakpoint and go to debug mode. (check the documentation if you do not know how to debug your scripts)
If the first if-branch gets entered, something with your animation is wrong. Otherwise you have to find out, why it is not entered.
yeah it doesnt seem to be getting entered. Its really confusing me.
I actually went to another script that uses the right mouse, which is my Aim Down Sight script, and I added a debug console and the code there, and just as a saftey net kept the old code the same. It works now. Thanks.
Answer by regie · Jul 18, 2012 at 02:23 PM
I think you just have to correct the first line: if(Input.GetButtonDown("Fire2") && Input.GetButtonDown("Fire1"))