Image Flip/Rotations with the mouse above/below 90/-90 degrees to the point. How do I accomplish this?

Hello everyone,
I have been stuck on a problem with image rotation/flipping based on mouse position tracking. the 2 videos below depict what I want the rotation/flip to look like, then what it currently is doing.
The first video is showing a simple code I constructed using Game Maker. I am relatively new to Unity and have been trying to solve this issue for a while. None of the scripts I have found thus far have helped. The Second image is what I have been able to do in Unity. It is able to track the mouse’s position and rotate towards it using the following script.

Goal - - YouTube
Current - - YouTube

What should i use to alter the direction in which the image is facing?
Or better yet, how do i flip the entire player to always face towards the mouse position and rotate the weapon towards the mouse target while still maintaining the desired animations?
This is a loaded question and again, i apologize for being new. I’m learning and I am trying to solve this issue, but I could really use some help.
Thank you for your time! !

//Variables for positions
    public Vector3 mousePosition;
    public Vector3 gunPos;
    public float angle;

 void Update()
    {
        faceMouse();
    }

    void faceMouse()
    {
        Vector3 mousePosition = Input.mousePosition;
        mousePosition = Camera.main.ScreenToWorldPoint(mousePosition);

        Vector2 direction = new Vector2(
            mousePosition.x - transform.position.x, mousePosition.y - transform.position.y);
        transform.right = direction;

    }

Z-axis in 2D is for flipping image. Like in mirror if you have z-xis = 180 or -180.

It would be something like this.

    void faceMouse()
    {
        Vector3 mousePosition = Input.mousePosition;
        mousePosition = Camera.main.ScreenToWorldPoint(mousePosition);
        if (mousePosition.x > transform.position.x) // Mouse on the left of character
            //Flip image normal
            transform.localRotation.z = 0;
        else // Mouse on the right of character
            //Flip image 180 in z axis
            transform.localRotation.z = -180;
        Vector2 direction = new Vector2(
        mousePosition.x - transform.position.x, mousePosition.y - transform.position.y);
        transform.right = direction;     
    }

So i have tried coding it with a similar formula to what you placed however I am having difficulty with the
transform.localRotation.z lines. It states that it “Cannot modify the return value of ‘Transform.localRotation’ because it is not a variable”. Again since I’m trying to learn I have attempted a few fixes, none of which have worked. I understand what your code is trying to do, I don’t understand however, why the engine is unable to recognize the transform component and carry out the rotation. It being in a void should not require a return value to modify or a variable to assign the value to.
Do you have any further suggestions as to how to fix this?

Again, i appreciate you assisting me with this.