Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by superpentil · Jul 18, 2012 at 07:42 AM · animationgameobjectinputbuttons

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");
  }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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?

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image superpentil · Jul 18, 2012 at 07:34 PM 0
Share

Yes, Ill try your suggestion and the one below.

avatar image superpentil · Jul 18, 2012 at 07:41 PM 0
Share

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.

avatar image senad · Jul 19, 2012 at 08:51 AM 0
Share

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.

avatar image superpentil · Jul 28, 2012 at 02:05 AM 0
Share

yeah it doesnt seem to be getting entered. Its really confusing me.

avatar image superpentil · Jul 28, 2012 at 02:12 AM 0
Share

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.

avatar image
0

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"))

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How could it be done "Cooldown" for a shield ? 2 Answers

Animation clips not staying with Character 0 Answers

Control the Animation 1 Answer

How to add touchscreen controls to this script? 0 Answers

Animation (Legacy) SetCurve() to target GameObject active state 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges