Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How do I Transition 2D animations when using Input.GetKey?

Discussion in 'Scripting' started by JustaDuck97, Oct 12, 2019.

  1. JustaDuck97

    JustaDuck97

    Joined:
    Jul 31, 2019
    Posts:
    45
    Code (CSharp):
    1. public class PlayerMovement : MonoBehaviour
    2. {
    3.     //Variables
    4.     public float Movespeed = 0.05f;
    5.     public float Jumpheight = 0.05f;
    6.     public Animator animator;
    7.  
    8.  
    9.     void Update()
    10.     {
    11.         if (Input.GetKey(KeyCode.D))
    12.  
    13.             {
    14.             transform.Translate(Vector3.right * Movespeed, Space.Self);
    15.            };
    16.         if (Input.GetKey(KeyCode.A))
    17.         {
    18.             transform.Translate(Vector3.left * Movespeed, Space.Self);
    19.    
    20.         }
    21.         if (Input.GetKey(KeyCode.Space))
    22.         {
    23.             transform.Translate(Vector3.up * Jumpheight, Space.Self);
    24.         }
    25.  
    26.         animator.SetFloat("Speed", );
    27.  
    28.     }
    29. }


    EDIT: Nevermind, I forgot .bool was a thing.
     
    Last edited: Oct 13, 2019