Rotate Object with with mouse

Hi

I found the script below here in the forum.
It works great but it turns the object around itself, means, once it’s back is front, moving the mouse up becomes down and the other way around.
I would need to modify it to use Space.World but can not figure it out.

var speed : int;

var friction : float;

var lerpSpeed : float;

private var xDeg : float;

private var yDeg : float;

private var fromRotation : Quaternion;

private var toRotation : Quaternion;

function Update ()
{
if(Input.GetMouseButton(0)) {

    xDeg -= Input.GetAxis("Mouse X") * speed * friction;

    yDeg += Input.GetAxis("Mouse Y") * speed * friction;

    fromRotation = transform.rotation;

    toRotation = Quaternion.Euler(yDeg,xDeg,0);

    transform.rotation = Quaternion.Lerp(fromRotation,toRotation,Time.deltaTime  * lerpSpeed);

}

}

Try using transform.Rotate instead. Something like this should work (c#, but the principle is the same):

using UnityEngine;

public class Rotate : MonoBehaviour
{
	public float RotationSpeed = 5;
	
	// Update is called once per frame
	void Update () 
	{
		transform.Rotate((Input.GetAxis("Mouse X") * RotationSpeed * Time.deltaTime), (Input.GetAxis("Mouse Y") * RotationSpeed * Time.deltaTime), 0, Space.World);
	}
}

I’d suggest switching the X and Y axes to make the rotation more intuitive (i.e. dragging the mouse left-right to rotate the object left-right instead of up-down) but that depends on your intention of course.