1 Answer
1Hello @Slaimi ! My guess would be that this is what you want :
using UnityEngine;
public class Rotator : MonoBehaviour
{
public float Sensitivity;
private Vector3 objectPositionToScreen;
private Vector3 mousePosition;
private void Start()
{
objectPositionToScreen = Camera.main.WorldToScreenPoint(transform.position);
}
void Update()
{
objectPositionToScreen = Camera.main.WorldToScreenPoint(transform.position);
if (Input.mousePosition.x > objectPositionToScreen.x)
transform.Rotate(0, Vector3.Magnitude(Input.mousePosition - objectPositionToScreen) * 0.01f * Sensitivity, 0);
else
transform.Rotate(0, Vector3.Magnitude(Input.mousePosition - objectPositionToScreen) * 0.01f * (-Sensitivity), 0);
}
}
This script needs to be attached on the object you want to rotate.
Short explanation : The object will rotate to left if your mouse cursor will be on the left side of the object and it will rotate to right otherwise. You can use the Sensitivity to adjust the rotation speed in accordance to your needs. Have a good day !

You can add "-" before Sensitivity in the "if" section, and remove "-" before Sensitivity in the "else" section. That will cause the object to spin in reversed directions relative to y axis and this should be the appropiate effect.
– Casy10