Problem in 2D Gun Rotation

Hello everyone

14042-errrrrrr.png

as u can see in picture

when i aim in the right side
my Gun is Okey

but when i look/aim at the left side
my Weapon Flipped Vertical

Used Code :

    private var mousePos : Vector2;
    private var screenPos : Vector3;
     
    function Update () {
    
    
   mousePos = Input.mousePosition;
   screenPos = Camera.main.ScreenToWorldPoint(Vector3(mousePos.x, mousePos.y, transform.position.z - Camera.main.transform.position.z)); 
   transform.rotation.eulerAngles.z = Mathf.Atan2((screenPos.y - transform.position.y), (screenPos.x - transform.position.x))*Mathf.Rad2Deg;
  
  }

So this is a plane in 3D space with a texture applied? Why not just flip the texture on the Y axis by changing the scale? Have a look at SetTextureScale

renderer.material.SetTextureScale("_MainTex", new Vector2(1, -1));