using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class playercontroller : MonoBehaviour
{
private Rigidbody2D rb;
public float speed;
Animator anim;
public float jumpForce;
private bool aord; // (A or D)
void Start()
{
rb = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
}
void Update()
{
aord = (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.A));
if(Input.GetKey(KeyCode.D))
{
rb.velocity = new Vector2(speed, rb.velocity.y);
anim.SetBool("isRunning",true);
}
else if(Input.GetKey(KeyCode.A))
{
rb.velocity = new Vector2(-speed, rb.velocity.y);
anim.SetBool("isRunning",true);
}
else if (aord == false)
{
rb.velocity = new Vector2(0, rb.velocity.y);
anim.Play("Idle");
anim.SetBool("isRunning",false);
}
}
}