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
2
Question by sam 1 · Oct 24, 2010 at 04:14 PM · animationplaykeypressed

how to make a animation play only if you press a certain key?

I have a ak 47 gun model with an reloading animation. I dont want the reloading animaation to start right when i start playing my game. I only want my gun to start reloading when i press the key "r". How do i do this? Do I need some sort of script or something?

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

8 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by Jesus_Freak · Oct 24, 2010 at 04:57 PM

well, a script would work, it would be something like:

    function Update()
{
 if(Input.GetKeyDown("r"))
 {
  // Plays the reload animation - stops all other animations
  animation.Play("reload", PlayMode.StopAll);
 }
}

just so you know, you have to rename the "reload" animation to whatever you called it.

hope this helps.

Comment
Add comment · Show 3 · 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 Proclyon · Oct 29, 2010 at 09:16 AM 0
Share

just go to Edit --> Project Settings --> Input, define the "r" key or whatever key you want and combine that with the answer above. You should have smooth sailing from there

avatar image Jesus_Freak · Oct 29, 2010 at 10:15 PM 0
Share

actually, Get$$anonymous$$eyDown becomes true whenever you press down on the keyboard key that you define, i gave you the r key, so when you press r, and if you set the variables, the reload animation should play. what Proclyon said would work with the GetButtonDown statement. but you don't HAVE to do that with the Get$$anonymous$$eyDown statement.

avatar image A-man tuna · Nov 16, 2012 at 01:09 PM 0
Share

can u please say how to put the variables and where, cuz this doesn't work, thank you =)

avatar image
1

Answer by sam 1 · Nov 07, 2010 at 04:27 PM

well guys this is what i did. i made the script and made a new input. I made a new javascript, called "reload", and copyed and pasted that script you gave me into it. Then copyed that script into my gun item thing. currently its in the hierarchy. my gun is also called "reload". i tried it and it didnt work. it kept saying: "the animtaion state reload could not be played because it couldnt be found!" so i tried the iput thing. i made a new input called reload. i put the postive key as "r". i tried it again and it didnt work. it said the same thing. "the animtaion state reload could not be played because it couldnt be found!" whats wrong? why cant it play it? why does it keep saying that? could some one help me?

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

Answer by Dummy7307 · Feb 04, 2011 at 03:25 PM

Do as Unity3_User says but change (Input.GetKeyDown) to (Input.GetButtonDown)

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

Answer by joe_coronado · Feb 01, 2012 at 09:12 PM

This happened to me it was because the animation name had a capital ' R'and the "reload" in the script doesnt. so check your capitals, this answer is for sam

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

Answer by DevDale · Mar 03, 2012 at 10:37 PM

How can I make this same affect apply for when I press a mouse button?

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 Kleptomaniac · Mar 03, 2012 at 11:42 PM 0
Share

For left mouse button: if (Input.Get$$anonymous$$ouseButtonDown(0)) {

For right mouse button: if (Input.Get$$anonymous$$ouseButtonDown(1)) {

For middle mouse button: if (Input.Get$$anonymous$$ouseButtonDown(2)) {

There you go, $$anonymous$$lep

  • 1
  • 2
  • ›

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

9 People are following this question.

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

Related Questions

Play animation when 2 keys pressed? 3 Answers

Play animation in child model 0 Answers

Play a video on clicking on an object 1 Answer

On collision play animation 1 Answer

Retrieving the name of the animation currently playing 9 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