Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Shrimpy · Jun 04, 2011 at 01:09 PM · animation

Animation On Button Press

Hi all, what i am trying to do is play an animation when a button is pressed, for example when the space-bar is pressed it plays a waving animation. I have already animated this in blender and imported it into unity but i dont know how i would play the animation when a certain button is pressed. I have very little scripting skills and all i know about this is it might have Get.ButtonDown in it, apart from that i am clueless, could anyone help me with this? Thank you

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Catlard · Jun 04, 2011 at 01:19 PM

Well, you'll have to set up the animation not to play by "default". If you highlight the object that you've animated in the project, then look down towards the bottom where it asks you if you want to split animations. You click the box, and it will create an animation with a name (by default "idle") and you'll need to specify the number of frames in your animation. Then, you can go into the script attached to the object, the one you want to cause the animation to play, and you use the code on this script reference page:

http://unity3d.com/support/documentation/ScriptReference/Animation.Play.html

However, it will play automatically unless you split the animation and give it a name.

Helpful, hopefully?

Cheers.

Comment
Add comment · Show 8 · 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 Shrimpy · Jun 04, 2011 at 01:38 PM 0
Share

The script which you have provided, does not do anything i have placed it on the object which is supposed to wave if this is what i am supposed to do, but nothing changes. i did everything else you said but that didnt seem to change anything either.

Thanks for posting though

avatar image Catlard · Jun 04, 2011 at 01:43 PM 0
Share

Well, you have to change "wave" to whatever name your animation has. Does that make sense?

avatar image Shrimpy · Jun 04, 2011 at 01:46 PM 0
Share

What do you mean change wave, my animation is called Wave

avatar image Catlard · Jun 04, 2011 at 02:37 PM 0
Share

I don't know, but it can't be good! Name it Fisheggs or something else.

Why don't you show me your code?

avatar image Shrimpy · Jun 04, 2011 at 02:41 PM 0
Share

// Plays the Wave animation - stops all other animations in the same layer animation.Play("Wave"); // Plays the Wave animation - stops all other animations animation.Play("Wave", Play$$anonymous$$ode.StopAll);

Show more comments
avatar image
0

Answer by Shrimpy · Jun 04, 2011 at 03:13 PM

This is my script

 // Plays the Wave animation - stops all other animations in the same layer
 animation.Play("Wave");
 // Plays the Wave animation - stops all other animations
 animation.Play("Wave",PlayMode.StopAll);
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
0

Answer by alex2018 · Nov 27, 2014 at 05:27 PM

hellow i have a code for activate animation with a press key

void Update () {

  if(Input.GetKeyDown("h"))
  animation.Play ();

 }
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 shecky911 · Feb 22, 2016 at 10:41 PM 0
Share

Thank you! I just spent two hours trying to get this to work and was so frustrated. Can you tell me how I would add on to this to target a specific animation rather than the only one I have present? Cheers!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Animation script with is.grounded help 0 Answers

change animation name in inspector 2 Answers

Animation component in Unity 4.3 doesn't work? 2 Answers

Animation Problems 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