using System.Collections;
using System.Collections.Generic;
[RequireComponent(typeof(Rigidbody2D))]
public class PlayerController : MonoBehaviour
public Directions currentDirection;
public Animator animator;
private float horizontal;
[SerializeField] private float moveSpeed;
rb = GetComponent<Rigidbody2D>();
private void FixedUpdate()
rb.velocity = new Vector2(horizontal, vertical) * moveSpeed;
if (Input.GetKey(KeyCode.W))
currentDirection = Directions.Up;
else if (Input.GetKey(KeyCode.S))
currentDirection = Directions.Down;
else if (Input.GetKey(KeyCode.D))
currentDirection = Directions.Right;
else if (Input.GetKey(KeyCode.A))
currentDirection = Directions.Left;
if(horizontal != 0f || vertical != 0f)
animator.SetBool("walking", true);
animator.SetBool("walking", false);
switch (currentDirection)
animator.SetFloat("horizontal", 0f);
animator.SetFloat("vertical", 1f);
animator.SetFloat("horizontal", 0f);
animator.SetFloat("vertical", -1f);
animator.SetFloat("horizontal", -1f);
animator.SetFloat("vertical", 0f);
animator.SetFloat("horizontal", 1f);
animator.SetFloat("vertical", 0f);