Question by 
               Queee · Feb 14, 2017 at 12:15 AM · 
                animationscripting beginnerscriptingbasics  
              
 
              How to make a animation play when I press a key
Hey im trying to make a walking animation play when i press w,a,s,d (for a top down 2d game)
I have been looking around for a while and i could not fund anything.
Here's my code (some of it is pointless because I did not delete the other ways I tried)
 using UnityEngine;
 using System.Collections;
 
 public class PlayerController2D : MonoBehaviour
 {
 
     public int moveSpeed;
     public int jumpHeight;
     public int Crouch;
 
     public Transform groundPoint;
     public float radius;
     public LayerMask groundMask;
 
     public float speed;
     public bool animation_bool;
 
     Animator anim;
 
     bool isGrounded;
     Rigidbody2D rb2D;
 
     
 
 
     void Start()
     {
         rb2D = GetComponent<Rigidbody2D>();
         anim = GetComponent<Animator>();
     }
 
 
     void Update()
     {
         Vector2 moveDir = new Vector2(Input.GetAxisRaw("Horizontal") * moveSpeed, rb2D.velocity.y);
         rb2D.velocity = moveDir;
 
 
 
         isGrounded = Physics2D.OverlapCircle(groundPoint.position, radius, groundMask);
 
         anim.SetFloat("speed", Mathf.Abs(Input.GetAxis("Horizontal")));
 
 
 
         if (Input.GetAxisRaw("Horizontal") == 1)
         {
             transform.localScale = new Vector3(1, 1, 1);
         }
         else if (Input.GetAxisRaw("Horizontal") == -1)
         {
             transform.localScale = new Vector3(-1, 1, 1);
         }
         GetComponent<ConstantForce>().enabled = false;
         
         if (Input.GetKeyDown(KeyCode.Space) && isGrounded)
         {
             rb2D.AddForce(new Vector2(0, jumpHeight));
         }
         if (Input.GetKeyDown(KeyCode.W))
 
             GetComponent<Animator>().SetBool("Walking up", true);
 
     }
         }
               Comment
              
 
               
              Answer by TeohRIK · Feb 14, 2017 at 02:56 AM
u can try to use 2d blend tree animation
OH wait i looked up a video. Thanks for the answer lets see if it works!
Your answer
 
 
             Follow this Question
Related Questions
Clarifaction needed on LoadLevel delay. 1 Answer
Set Bool to false after seconds? 2 Answers
How To Add Animations Through C# Scripts 0 Answers
Play animation on mouseclick 0 Answers
How to make a bowling pin setter without any scripting 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                