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 DizzyTornado · Nov 17, 2013 at 03:16 AM · animationfpsanimations

how to make an animation play on input

So I have the fps control (by tornado twins) asset from the store and it comes with all the nescessary animations for an m16 but i don't know how to make the animations play on an input. For example: you make the reload animation play when you press R, fire the gun when you press the left mouse button, or run the sprint animation when you press Shift+w,a,s,d, Thanks in advance.

Comment
Add comment · Show 1
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 Im-Brazilian · Nov 17, 2013 at 04:45 AM 0
Share

Reload:

 function Update()
 {
  if(Input.Get$$anonymous$$ey("r"))
  {
  
   animation.Play("ANI$$anonymous$$ATON_NA$$anonymous$$E");
  }
 }

Fire :

 function Update()
 {
  if(Input.Get$$anonymous$$ouseButtonDown(0))
  {
  
   animation.Play("ANI$$anonymous$$ATON_NA$$anonymous$$E");
  }
 }

Run (front):

 function Update () {
  
     if  (Input.Get$$anonymous$$ey($$anonymous$$eyCode.LeftShift) && Input.Get$$anonymous$$ey($$anonymous$$eyCode.W))
     animation.Play("ANI$$anonymous$$ATION_NA$$anonymous$$E");
 }

Run (back):

 function Update () {
  
     if  (Input.Get$$anonymous$$ey($$anonymous$$eyCode.LeftShift) && Input.Get$$anonymous$$ey($$anonymous$$eyCode.S))
     animation.Play("ANI$$anonymous$$ATION_NA$$anonymous$$E");
 }

Run (LeftSide):

 function Update () {
  
     if  (Input.Get$$anonymous$$ey($$anonymous$$eyCode.LeftShift) && Input.Get$$anonymous$$ey($$anonymous$$eyCode.A))
     animation.Play("ANI$$anonymous$$ATION_NA$$anonymous$$E");
 }

Run (RightSide):

 function Update () {
  
     if  (Input.Get$$anonymous$$ey($$anonymous$$eyCode.LeftShift) && Input.Get$$anonymous$$ey($$anonymous$$eyCode.D))
     animation.Play("ANI$$anonymous$$ATION_NA$$anonymous$$E");
 }

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Im-Brazilian · Nov 17, 2013 at 05:54 AM

Reload:

 function Update()
 {
  if(Input.GetKey("r"))
  {
  
   animation.Play("ANIMATON_NAME");
  }
 }

Fire :

    function Update()
 {
  if(Input.GetMouseButtonDown(0))
  {
 
   animation.Play("ANIMATON_NAME");
  }
 }

Run (front):

 function Update () {
   
     if  (Input.GetKey(KeyCode.LeftShift) && Input.GetKey(KeyCode.W))
     animation.Play("ANIMATION_NAME");
 }

Run (back):

 function Update () {
   
     if  (Input.GetKey(KeyCode.LeftShift) && Input.GetKey(KeyCode.S))
     animation.Play("ANIMATION_NAME");
 }



Run (LeftSide):

 function Update () {
   
     if  (Input.GetKey(KeyCode.LeftShift) && Input.GetKey(KeyCode.A))
     animation.Play("ANIMATION_NAME");
 }

Run (RightSide):

 function Update () {
   
     if  (Input.GetKey(KeyCode.LeftShift) && Input.GetKey(KeyCode.D))
     animation.Play("ANIMATION_NAME");
 }










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 DizzyTornado · Nov 17, 2013 at 04:18 PM 0
Share

i just tried the reload script. It didnt seem to work. What i did was i added the animation and script to the fps controller. Do I need to make the animation's name a variable? Thanks in advance.

avatar image
0

Answer by DizzyTornado · Nov 17, 2013 at 06:38 AM

Thank you a lot. I'm just wondering what the different mouse buttons are called? I assume mousebutton0=left mouse button and mousebutton1=right mouse button but I'm not sure. Thanks again.

Comment
Add comment · Show 4 · 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 Im-Brazilian · Nov 17, 2013 at 04:36 PM 1
Share

left button mouse : Get$$anonymous$$ouseButton (0)

right button mouse : Get$$anonymous$$ouseButton (1)

middle button mouse : Get$$anonymous$$ouseButton(2)

and if you want to press a key (a,w,p,r,y....) you use Get$$anonymous$$ey("A LETTER")

example:

funtion Update () {

if (Input.Get$$anonymous$$ey("r")) { animation.Play("reload"); } }

avatar image DizzyTornado · Nov 17, 2013 at 05:05 PM 0
Share

Thanks alot.

avatar image DizzyTornado · Nov 17, 2013 at 05:06 PM 0
Share

i think this will efinitely help with my game.

avatar image Im-Brazilian · Nov 17, 2013 at 08:10 PM 0
Share

haha i'm brazilian i dont know if you really understand alll what i wrotten.

but i read "Thanks a lot" so...You're Welcome

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

19 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Animation are not fluid in android 1 Answer

Change the first frame of an animation 1 Answer

Why does Unity animator makes calling children's SetActive fail? 0 Answers

1 FPS in Unity Timeline 0 Answers

How to run an animation clip on button down-hold? 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