most likely last question for my 2d platformer game how do i make my weapon point where my mouse is

i know theres tutorials about this i even somehow had it working with a different game that was a space shooter but its not working on my platformer so here is the code

void FixedUpdate()
    {
        Vector3 difference = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
        float rotZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg;
        transform.rotation = Quaternion.Euler(0f, 0f, rotZ + offset);
    }

and that’s on a child of my player called rotate gun and rotate gun has the weapon as a child

You forgot to mention what isn’t working. Is it not rotating at all? Is it rotating the wrong way? Also, this shouldn’t be in FixedUpdate as it doesn’t appear to be code related to the physics system.

the weapon is rotating but its looking at the center of the camera so if the center is to its left its going to look at the left and i tried the code on void update too it still didnt work

found out the problem but if i want some sort of parallax in my game this is a problem but im fine with not having it the code is seriously just for 2d mode it wont work in 3d so got my answer on how to fix it for 2d