using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class characterMove : MonoBehaviour
{
public float moveSpeed;
private Animator anim;
private Rigidbody2D rb2d;
float moveHorizontal;
public bool facingRight;
// Start is called before the first frame update
void Start()
{
moveSpeed = 3;
moveHorizontal = Input.GetAxis("Horizontal");
anim = GetComponent<Animator>();
rb2d = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
characterMovement();
characterAnimation();
characterAttack();
characterRun();
}
void characterMovement()
{
moveHorizontal = Input.GetAxis("Horizontal");
rb2d.velocity = new Vector2(moveHorizontal * moveSpeed, rb2d.velocity.y);
}
void characterAnimation()
{
if (moveHorizontal > 0)
{
anim.SetBool("isWalking", true);
}
if (moveHorizontal == 0)
{
anim.SetBool("isWalking", false);
}
if (moveHorizontal < 0)
{
anim.SetBool("isWalking", true);
}
if(facingRight==false&&moveHorizontal>0){
characterFlip();
}
if(facingRight==true&&moveHorizontal<0){
characterFlip();
}
}
void characterFlip(){
facingRight = !facingRight;
Vector3 Scaler = transform.localScale;
Scaler.x *= -1;
transform.localScale = Scaler;
}
void characterAttack(){
if(Input.GetKeyDown(KeyCode.E)){
anim.SetTrigger("isAttack");
}
}
void characterRun(){
if(Input.GetKeyDown(KeyCode.LeftControl)){
anim.SetTrigger("isRun");
}
}
}