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 ash_05 · Sep 09, 2014 at 01:08 PM · c#animationanimator

control animation using animation control class

I did a sample existing code to control animation using animation.I dragged and dropped a character into the scene then I added a Animator to it and added the animator controller.Below I have given the screen short of the animationalt text

Then I have attached the following code to it

 Animator animator;
     int eatHash=Animator.StringToHash("Jump");
  int stateHash=Animator.StringToHash("Base Layer.idle");
 
     void Start () {
 
         animator = GetComponent<Animator>();
     
     }
     
     // Update is called once per frame
     void Update () {
     
         //animator.SetBool ("isEat", true);
         float move = Input.GetAxis ("Vertical");
         animator.SetFloat ("Speed",move);
 
         AnimatorStateInfo stateinfo = animator.GetCurrentAnimatorStateInfo (0);
         if (Input.GetKeyDown(KeyCode.Space))
 
         {
             Debug.Log ("clicked spacebar");
             animator.SetTrigger(eatHash);
                 }
                 
 }


The problem here is the above code is working,when I run the project the animation is getting played one after the another according to the state diagram.But when I click on the space bar the trigger function(jump animation ) is not working

 if (Input.GetKeyDown(KeyCode.Space))
 
         {
             Debug.Log ("clicked spacebar");
             animator.SetTrigger(eatHash);
                 }

animation.png (23.6 kB)
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
0
Best Answer

Answer by HarshadK · Sep 09, 2014 at 01:11 PM

The Jump state has a transition only from idle state. So on pressing Jump the jump state animation will only be played if the character is currently in idle state.

If you want to transition from any other state to jump state then you need to create such transitions between stated in the animator.

Comment
Add comment · Show 6 · 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 ash_05 · Sep 10, 2014 at 04:02 AM 0
Share

@Harshad : Thanks a lot for the valuable reply.Can you help me how to create transition between states.You mean whether i need to add transition form all the states to the jump state.

avatar image HarshadK · Sep 10, 2014 at 05:13 AM 0
Share

Create a transition from 'Any State' to your jump state.

Watch this s$$anonymous$$lth tutorial for PLAYER ANI$$anonymous$$ATOR CONTROLLER.

avatar image ash_05 · Sep 10, 2014 at 11:09 AM 0
Share

From the above transition diagram i have removed the transition link between each state and only given link between Any State and idle.This will work fine?

avatar image ash_05 · Sep 10, 2014 at 12:12 PM 0
Share

@Harshadk : I made the transition from Any State to jump but still not working

avatar image HarshadK · Sep 10, 2014 at 02:21 PM 0
Share

You also need to make a transition from your current states to Any State.

Also, did you check the s$$anonymous$$lth video tutorial I provided above?

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

2 People are following this question.

avatar image avatar image

Related Questions

animation control problem 0 Answers

Is there an isPlaying() type function for Animator 2 Answers

How can i use the Animator in script to find when animation clip finished playing and then stopping the animation ? 1 Answer

Conflicting Animator SetTrigger 0 Answers

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