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 snowconesolid · Jan 02, 2012 at 06:35 AM · animationjavascripting

Play Different Animation Using the Same Key Press?

I have been trying to figure out a solution to this for hours but just cannot. I want to be able to play a different animation using the same key press.

heres what Im doing so far, if the player is holding down the Up key then play the default animation.

heres what I want to do, if the player collides with this object then disable the default animation, if the player is holding the up key play the new animation.

I am using two different scripts, one for movements and one for collision. The movement script has the default animation inside of it and the collision script has the new animation in it.

I thought for sure it would work if I stop the default animation on collision and then putting, if user holds up key play new animation, but it didnt.

I have also tried combining the two but no luck.

We need a animation.Disable and animation.Enable function or something like it. I could of just put this in my script,

if the user collides with this object then animation.disable("DefaultAnimation"); animation.enable("NewAnimation"); if user holds up key play new animation. Or something like that.

so how to play different animation using the same button press?

Anyway any solutions/feedback/help to my problem will be very much appreciated.

anyone who can help me solve this wins a Well-Done Steak, mash potatoes and a Cherry Icee.

EDIT: After making this post I just had to go and submit the idea for a animation.disable and animation.enable function in scripting. so if you think its a good idea vote for it please

http://feedback.unity3d.com/forums/15792-unity/suggestions/2485428-enable-and-disable-animations-in-script

IMO this feature would make a lot of things easier and would be extremely useful to have.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by robert_mathew · Jan 02, 2012 at 07:28 AM

  Public Animation  player_animation;

  Public bool            p_bool_anima1;
  Public bool            p_bool_anima2;
  Public bool            p_bool_anima1 3;

  void Update()
                     {

                   if( Input.GetButtonDown("Right") && p_bool_anima1 == true)
                                                        {
                                                 p_bool_anima1 = false;
                                                 player_animation.Play("walk");
                                                         }


                   if( Input.GetButtonDown("Right") && p_bool_anima2 == true)
                                                        {
                                                 p_bool_anima2 = false;
                                                 player_animation.Play("sit");
                                                         }

                    if( Input.GetButtonDown("Right") && p_bool_anima3 == true)
                                                        {
                                                 p_bool_anima3 = false;
                                                 player_animation.Play("idle");
                                                         }

                     }

make this bool true where ever you want other bool false where you want any question means ask

Comment
Add comment · Show 7 · 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 kievar1983 · Jan 02, 2012 at 08:03 AM 0
Share

ditto, upvote!

avatar image snowconesolid · Jan 02, 2012 at 05:30 PM 0
Share

hmm im a little confused with this script, how do I make this work with 2 different scripts? I want my default animations to always play, but on collision with an object I want my collision script to disable the default animations in the move script and enable the animations in the collision script?

EDIT: Looks like there is a function similar to the one I was talking about

// Enable the walk cycle animation["Walk"].enabled = true; animation["Walk"].weight = 1.0;

but it still didnt work the way I want it to, the default animation still plays when holding the up key even if I disable it after the collision. for some reason the only way I can change to the new animation is if I completely remove the default animation.

avatar image naf456 · Jan 02, 2012 at 07:10 PM 0
Share

switch statement anyone?

avatar image snowconesolid · Jan 02, 2012 at 09:31 PM 0
Share

I know what a switch statement is and how to use it, but I still dont understand how to use this code. I dont get how to switch between my 2 scripts.

avatar image robert_mathew · Jan 03, 2012 at 05:11 AM 0
Share

make the boolean as static and will able to access it from any script

Show more comments

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

7 People are following this question.

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

Related Questions

AnimationClip and AnimationState 0 Answers

I have a problem in ex2D animationsprites. 1 Answer

fbx animation to> blender 1 Answer

Need help with Animations 1 Answer

Cloud recognition in Vuforia 0 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