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 JayMHelpsU · Apr 12, 2012 at 06:35 AM · animationjavascriptkeydown

Player Animation HELP REQUIRED PLEASE

I have two different animations both linked to one GameObject (MainPlayer). i made a script for it to play the running animation when "w" is held, when its let go play standing. This is the code i have but it doesnt play the standing :( If Anybody could help that would be awesome.

function Update () {
    if (Input.GetKeyDown ("w"))
        {
            //gameObject.animation.Stop(Stand);
            gameObject.animation.CrossFade("Walking");            
        }
    if (Input.GetKeyUp ("w"))
        {
            //gameObject.animation.Stop(Walk);
            gameObject.animation.CrossFade("Standing");
        }
}

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by venkspower · Apr 12, 2012 at 06:40 AM

Instead of using animation.CrossFade(), use animation.Play().

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 fafase · Apr 12, 2012 at 06:42 AM

I would think you main problem is the input yu are using. GetKeyDown only returns true on the frame it goes down meaning only once and then back to 0. I think what you want is GetKey which returns true as long as you are pressing the key. If you release the else takes place and the animation is standing.

    function Update () {  
        if (Input.GetKey ("w"))  {  
            animation.CrossFade("Walking",0.2f);  
       }   
       else{
            animation.CrossFade("Standing",0.2f);  
       } 
     }

Not really sure though which of GetKey or GetButton is right...The documentation does not really explain any differences..

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 JayMHelpsU · Apr 12, 2012 at 08:54 AM 0
Share

mmm thanks, what is happening is that when i let go of the "w" it stops playing the Walking but doesnt start playing the Standing. Thanks for the help... I'll get back to you on the Status :)

avatar image fafase · Apr 12, 2012 at 08:59 AM 0
Share

Could be the length of your animation that is too short see this http://answers.unity3d.com/questions/165123/animation-crossfade-wont-play-but-animation-play-d.html Try removing the 0.2f (though they should work) or use animation.Play() and see how it goes.

avatar image JayMHelpsU · Apr 12, 2012 at 12:52 PM 0
Share

Sadly same result :/ I'm not sure whati can do?

avatar image fafase · Apr 12, 2012 at 01:37 PM 0
Share

mmm are you sure the animation is attached/written properly/simply doing anything? (we never know...)

avatar image fafase · Apr 13, 2012 at 07:39 AM 0
Share

Since the first goes fine, swap the animations and see if your guy is "standing animating" when you press.

If not, that means it comes from the animation itself and you would have solved 1/2 of the pb.

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

6 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

How to make a animation rotation js.script? 2 Answers

animation.Play isn't working 1 Answer

Why cant i get my animation to play? 0 Answers

Climb animation is glitchy and isnt working properly 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