How to change transform.position.x after a state is changed?

When I press attack button, player will change to Normal Attack state to perform Normal Attack animation and you will notice the player seem like step back a little bit as the width of sprite for Normal Attack animation is longer than Idle animation.

To solve this issue. I need to change the transform.position.x =+ 0.5 to move a bit further to match the position of Idle animation stands and transform.position.x =- 0.5 when Normal Attack state done its animation and back to Idle state. How can I perform transform.position.x =- 0.5 when when Normal Attack state done its animation and back to Idle state?

You should not try to do this in code; you should fix your sprites so the player’s centre is aligned in all of them.

But if you must, you could set a flag (let’s call it justAttacked) to true and move the player when your player presses the attack button, and then in your update function, do this (assuming your attack animation is called attackAnimation:

if(attackAnimation.isPlaying() == false && justAttacked == true){
    transform.position.x -= 0.5;
    justAttacked = false;

}