Lock character's LocalScale during Idle animation

Hi, I would appreciate some suggestions for the following problem;
I’ve got a character with two basic animations, Walk and Idle. During Walk animation you can see the side of the character, while during Idle animation the character is facing the camera.
The flip method functions correctly while walking. However, it somewhat disfigures the character during idle animation when the scale is set to -1. I’d like to lock the character’s x scale to +1 when he’s idling.
My solution was to add the following animation behavior to the Idle animation.

public class KeepScaleBehaviour : StateMachineBehaviour {

    private Transform playerTransform;
    private GameObject player;
    float updatedXscale;

    override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        player = GameObject.FindWithTag("Player");
        playerTransform = player.GetComponent<Transform>();

        if (playerTransform.localScale.x > 0)
            return;

        else
            playerTransform.localScale = new Vector3(playerTransform.localScale.x * -1, playerTransform.localScale.y, playerTransform.localScale.z);
    }

    override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        if (Input.GetAxis("Horizontal") > 0)
            updatedXscale = 1;
        else
            updatedXscale = -1;

        playerTransform.localScale = new Vector3(updatedXscale, playerTransform.localScale.y, playerTransform.localScale.z);
    }
}

This behavior script seems to be doing the job, but I have a feeling that there’s a simpler or more efficient way of solving this issue.
Feel free to share any ideas. Thanks

I suggest you put in a check in the flip function of your character controller script—an if statement or a boolean—that checks whether your character’s rigidbody.velocity is greater than zero, and if so then the flip function can be executed. I haven’t tried it myself yet but I believe this is a viable option. The problem with your method is that firstly, it is costly to the performance if you have multiple character’s with the same state machine behaviour (the calculation is made every-time character enters idle state) and secondly there’s a lot of potential for unwanted behaviour, especially when you add more animation layers or clips.