• 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 DryTear · Mar 30, 2013 at 10:32 PM · buttonanimationsgunplaywhen

Gun Animations

How to make a script that manages what animations to play on the gun based on what button is pressed.

Comment
Add comment · Show 6
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 joeyaaaaa · Mar 30, 2013 at 10:34 PM 0
Share

if input this button do this animation if input this button{ this animation } so on but have it send to the same function you use for firing, unless you also shoot different bullets, then just do different things, use complete new input detection for each action edit--managing, when pushing a specific button have it send the name to a function that says if this name is this do this or if this name is that do this very vague answer lol but basic idea is there

avatar image DryTear · Mar 30, 2013 at 10:45 PM 0
Share

a basic is idea is what i need i dont need a script that can make my gun do complex stuff, i just need one if statement to get me started

avatar image joeyaaaaa · Mar 30, 2013 at 10:55 PM 0
Share
 if(input.GetButton("attack")|| input.GetButton("attack2")||input.GetButton("attack3") && sometTime < Time.time ) {
 if(input.GetButton("attack"){
 //do this
 //someTime = Time.time + 2;
 if(input.GetButton("attack2"){
 //do this
 //someTime = Time.time + 2;
 }
 if(input.GetButton("attack3"){
 //do this
 //someTime = Time.time + 2; 
 }
 }
 }

i have a feeling this isnt what you meanbut its all i can come up with lol

avatar image DryTear · Mar 30, 2013 at 11:42 PM 0
Share

just what i need - i just gotta change the comments to animation.Play(variable);

avatar image joeyaaaaa · Mar 30, 2013 at 11:44 PM 0
Share

yes exactly hehe but lookign at this is slightly redundant, idont think you have to check each button with the || symbols, just remove that and its bracket, and check fo rany and base it off that as you would normally

avatar image DryTear · Mar 31, 2013 at 02:24 AM 0
Share

thats what i do - i never use the doublewalls. $$anonymous$$d if u post an answer and ill accept it

1 Reply

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

Answer by DryTear · Apr 01, 2013 at 03:17 AM

So i decided to answer it my self:

 var shoot : Animation;
 var sprint : Animation;
 var idle : Animation;
 var aim : Animation;
 var aimshoot : Animation;

 function Update(){
 if(Input.GetButtonDown("Sprint"))
 {
     animation.Play(sprint);
 }
 else if(Input.GetButtonUp("Sprint"))
 {
     animation.Play(idle);
 }
 if(Input.GetButtonDown("Shoot"))
 {
     animation.Play(shoot);
     if(Input.GetButtonDown("Aim"))
     {
         animation.Play(aimshoot);
     }
 }
 else if(Input.GetButtonUp("Shoot"))
 {
     animation.Play(idle);
 }
 if(Input.GetButtonDown("Aim"))
 {
     animation.Play(aim);
 }
 else if(Input.GetButtonUp("Aim"))
 {
     animation.Play(idle);
 }
 function Start(){
     animation.Play(idle);
 }
Comment
Add comment · Show 1 · 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 xXM7MDXx · Mar 18, 2016 at 07:15 PM 0
Share

how do i attach animation clips to it

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

13 People are following this question.

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

Related Questions

How do i make an animation play on key press? 3 Answers

enable Blur effect when Esc button pressed (Windows Phone 8) 1 Answer

Help with GUI clicking ??? 1 Answer

Two Animations With One Button Press 1 Answer

How do I get Button to play a random sound in Unity 5.0? 2 Answers


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