how to flip a character unity 2d code example

Example 1: how to make player flip when pressing a d unity 2d

void  Update ()
    {  //This short code makes player flip when the A and D or arrow keys are pressed.

        Vector3 charecterScale = transform.localScale;
        if (Input.GetAxis("Horizontal") < 0)
        {
            charecterScale.x = -10;
        } 
        if (Input.GetAxis("Horizontal") > 0)
        {
            charecterScale.x = 10;
        }
        transform.localScale = charecterScale;
    }

Example 2: unity c# flip sprite

public Camera cam;
   public Transform aimTransform;



Vector3 mousePosition = cam.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y));
        Vector3 aimDirection = (mousePosition - transform.position).normalized;
        float angle = Mathf.Atan2(aimDirection.y, aimDirection.x) * Mathf.Rad2Deg;
        aimTransform.eulerAngles = new Vector3(0, 0, angle);