Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Jkreyes312 · Dec 13, 2015 at 02:47 PM · 2d game2d animation

Unity 2D My animator won't transition between states? Any help would be extremely helpful

Look i have been working on this 2d game nothing special I'm just trying to make my sprite walk, jump and attack. I've made the animations in unity with it's animation window but in the animator the states won't transition. I tested during the play and it's not responsive, it occurs randomly after i press the right key. I would like to know how i can solve it and or if it's just a problem with my code which i have feeling it is so please help and thank you for any feedback. My code

 //these are the private types
 private Animator anim; //contains animator value
 private Transform pos;
 //these are the variables
 int hattack;
 int hidle;
 int hwalk;
 int hrun;
 int hjump;
 int hleft;
 bool facingleft;
 public int Health;
 // Use this for initialization
 void Start () {
     pos = GetComponent<Transform>();
     anim = GetComponent<Animator> ();//allows variable to be called out
     Health = 100;
     hidle = Animator.StringToHash("Idle");
     hwalk = Animator.StringToHash("Walk");
     hrun = Animator.StringToHash("Run");
     hjump = Animator.StringToHash("Jump");
     hleft = Animator.StringToHash("Left");
     hattack = Animator.StringToHash("Attack");
 }
  
    void Flip()
 {
     // Switch the way the player is labelled as facing
     if (facingleft == false ) {
         // Multiply the player's x local scale by -1
         Vector3 theScale = pos.localScale;
         theScale.x *= -1;
         pos.localScale = theScale;
     } else if (facingleft== true) {

         Vector3 theScale = pos.localScale;
         theScale.x *= 1;
         pos.localScale = theScale;
     }

 }
 // Update is called once per fram
 void Update () {
     //Seting input keys over here
         if (Input.GetKeyDown(KeyCode.Space))
         {
             if (anim.GetCurrentAnimatorStateInfo(0).IsName("Swing1"))
             {
                 anim.SetTrigger(hattack);
             }
         }
         if (Input.GetKeyDown(KeyCode.D))
         {
             if (anim.GetCurrentAnimatorStateInfo(0).IsName("Idle"))
             {
                 pos.position = new Vector3((pos.position.x + 1), pos.position.y, pos.position.z);
                 anim.SetBool(hidle, false);
                 anim.SetBool(hwalk, true);
             }

             /*facingleft = false;
             Flip();*/
         }
         if ((Input.GetKeyDown(KeyCode.A)))
         {
             if (anim.GetCurrentAnimatorStateInfo(0).IsName("Idle"))
             {
                 facingleft = true;
                 anim.SetBool(hleft, true);
                 anim.SetBool(hwalk, true);
                 pos.position = new Vector3(pos.position.x - 1, pos.position.y, pos.position.z);
                 Flip();

                 anim.SetFloat("Speed", -1);
             }
         }
         if ((Input.GetKeyDown(KeyCode.W)))
         {
             if (anim.GetCurrentAnimatorStateInfo(0).IsName("Idle"))
             {
                 pos.position = new Vector3(pos.position.x, pos.position.y + 1, pos.position.z);
                 anim.SetBool(hidle, false);
                 anim.SetBool(hjump, true);
             }
         }
         else
         {
             anim.SetBool(hidle, true);
             anim.SetBool(hrun, false);
             anim.SetBool(hjump, false);
             anim.SetBool(hwalk, false);

         }

} }

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

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Lighting system in pixel art 1 Answer

How to I create sudden movements using Unity's animator? 0 Answers

2D Animations Not Working After Building Game 1 Answer

Not playing animation after been hit by bullet 2 Answers

Left/Right movement 2D game,Why is this code to make my character move left/right not working? 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