Edit mouse look script to not be effected by rotation

Hello! Currently, I have found and am using a smooth, javascript MouseLook script which I will show below. Right now, the problem I am facing is trying to get the script to act normally no matter what the current rotation is. Here is the script:

var LookSensitivity : float = 5;
private var YRotation : float;
private var XRotation : float;
private var CurrentYRotation : float;
private var CurrentXRotation : float;
private var YRotationV : float;
private var XRotationV : float;
var SmoothDamper : float = 0.1;

function Update(){
YRotation += Input.GetAxis("Mouse X") * LookSensitivity;
XRotation -= Input.GetAxis("Mouse Y") * LookSensitivity;

XRotation = Mathf.Clamp(XRotation, -90, 90);

CurrentXRotation = Mathf.SmoothDamp(CurrentXRotation, XRotation, XRotationV, SmoothDamper);
CurrentYRotation = Mathf.SmoothDamp(CurrentYRotation, YRotation, YRotationV, SmoothDamper);

transform.rotation = Quaternion.Euler(CurrentXRotation, CurrentYRotation, 0);

}

Don’t get me wrong, the script works perfectly for its intentions, but right now, my player is able to walk around a round planet, but the script doesn’t really co-operate with that, since the script works globally, and not relatively. For example, I would want this script to work if the player was upside down, rightside up, ect… I hope you understand what I mean, what would be the best/easiest fix for my problem?

Couldn’t you place your camera with it’s script attached as a child of an empty object, then change the parent right upside down or whatever, in which the camera as a child is in?