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 gameplay4all · Jul 24, 2013 at 04:51 PM · animationidleidle animations

Why does my animation not play? idle overrules animation?

Hello,

I have problems with my animations: my "Stab" animation wont play and i think it is because of the idle because when I comment out the idle animation it plays just fine Here is my script:

 var player : GameObject;
 
 function Start () {
 player = GameObject.FindGameObjectWithTag("Player");
 }
 
 function Update () {
 if(player.GetComponent(CharacterMotor).grounded == false){
 animation.CrossFade("Jump",0.3,PlayMode.StopSameLayer);
 }
 else if(Input.GetKey(KeyCode.W)){
 animation.CrossFade("Run",0.3,PlayMode.StopSameLayer);
 }
 else if(Input.GetKeyUp(KeyCode.Mouse1)){
 if(player.GetComponentInChildren(Gathering).rightHandRes != null){
 if(player.GetComponentInChildren(Gathering).rightHandRes.isTool == true){
 Debug.Log("Has said to do animation ");
 animation.CrossFade("Stab",0.3,PlayMode.StopSameLayer);
 }
 }
 }
 
 else{
 animation.CrossFade("Idle",0.3,PlayMode.StopSameLayer);
 }
 }

I hope that someone can help me with this problem :)

Comment
Add comment · Show 6
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 chris_taylor · Jul 24, 2013 at 05:02 PM 0
Share

why not use unity's new animation system $$anonymous$$ecanim?

avatar image gameplay4all · Jul 24, 2013 at 05:09 PM 0
Share

yeah its about time that I learn thqt, do you know any good tutorials?

avatar image rowdyp · Jul 24, 2013 at 05:12 PM 0
Share

$$anonymous$$echanim is nice, but it has flaws, one major flaw is the lack of animation events, it made adding effects so much easier than having to code it into the curve.

avatar image chris_taylor · Jul 24, 2013 at 05:18 PM 0
Share

@rowdyp I saw a plugin for events in mecanim in the asset store, I haven't used it and don't remember what it is but if thats what you need then I would suggest looking for that as I find $$anonymous$$echanim very powerful.

avatar image gameplay4all · Jul 24, 2013 at 05:26 PM 0
Share

yes that is right i looked it up but it is 30 dollars :( so i would love to just see what i'm doing wrong in the above question :)

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Dugular7 · Jul 24, 2013 at 06:20 PM

The main problem I see here is that you are essentially calling the idle animation every frame.

Your run animation will work because you are looking for a constant press of the key W, but you are only doing a GetKeyUp for the stab (Which is fine and logical). So what is happening is that on the very next frame, it sees that there is no more GetKeyUp for the mouse button and reverting to the idle.

Therefore, your best bet would be to modify the final else line to say:

 else if(!animation.IsPlaying("stab")){
 animation.CrossFade("Idle",0.3,PlayMode.StopSameLayer);
 }

That way, it won't play idle until the stab animation is completed :) Just make sure the stab animation isn't a looping one!

Comment
Add comment · Show 2 · 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 Dugular7 · Jul 24, 2013 at 06:09 PM 0
Share

Except of course you'll need to capitalise the S on stab, which I forgot to do there!

avatar image gameplay4all · Jul 24, 2013 at 06:31 PM 0
Share

yes! it worked! thank you :) and the capitals dont matter that much because it was just an example because my animations are named in my native language. but thanks for the attention to details

avatar image
0

Answer by chris_taylor · Jul 24, 2013 at 05:20 PM

You could use Mecanim. Here is their tutorial for it. Although I think they have more features now that are not shown in this video, but it is still a good starting point.

Edit: I think by using PlayMode.StopSameLayer you are making the crossfade act the same way as just a normal 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 gameplay4all · Jul 24, 2013 at 06:04 PM 0
Share

oh i will check that out in a moment sounds as a possible solution. i'll report back.

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

18 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

Related Questions

Idle Animations, Player Walking 0 Answers

Player plays walking animation if I press a and d at the same time while standing still 2 Answers

Animated character making mesh move when idle-animation is playing 1 Answer

What's a good way to do multiple Idle animations? 2 Answers

How can I move between two idle animations for an NPC on a timer? 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