I’ve created 2 layers (face right and face left). When character facing left, it can move forward to left but with the animation of facing right’s backward. When moving backward, it will use facing right’s forward, appreciate somebody can advise, thanks.
void Update()
{
// listen to the animator
Player1Layer0 = Anim.GetCurrentAnimatorStateInfo(0);
// Screen border set up (X axis)
Vector3 ScreenBounds = Camera.main.WorldToScreenPoint(this.transform.position);
if(ScreenBounds.x > Screen.width - 70)
{
CanWalkRight = false;
}
if (ScreenBounds.x < 50)
{
CanWalkLeft = false;
}
else if (ScreenBounds.x > 50 && ScreenBounds.x < Screen.width - 70)
{
CanWalkRight = true;
CanWalkLeft = true;
}
//get the opponent's position
OppPosition = Opponent.transform.position;
//facing left or right of the Opponent
if(OppPosition.x > Player1.transform.position.x)
{
StartCoroutine(FaceLeft());
}
if (OppPosition.x < Player1.transform.position.x)
{
StartCoroutine(FaceRight());
}
// Walking left and right
if (Player1Layer0.IsTag("Motion"))
{
if (Input.GetAxis("Horizontal") > 0)
{
if (CanWalkRight == true)
{
Anim.SetBool("forward", true);
transform.Translate(WalkSpeed, 0, 0);
}
}
if (Input.GetAxis("Horizontal") < 0)
{
if (CanWalkLeft == true)
{
Anim.SetBool("backward", true);
transform.Translate(-WalkSpeed, 0, 0);
}
}
}
if (Input.GetAxis("Horizontal") == 0)
{
Anim.SetBool("forward", false);
Anim.SetBool("backward", false);
}

