Skip to main content
1 of 5

Unity - How to calmp a rotation axis?

I want to rotate an object based on mouse delta but I am unable to clamp it because I only want it to turn so far on a specific axis.

Vector2 inputAxis;
GameObject obj;
//
//
//
obj.transform.rotation *= Quaternion.AngleAxis(inputAxis.y,Vector3.Right);
obj.rotation.eulerAngles = new Vector3(Mathf.Clamp(obj.rotation.eulerAngles.x,45,45),obj.transform.rotation.y,obj.transform.rotation.z);

Just results in an error code "Cannot modify the return value of 'Transform.rotation' because it is not a variable." I've googled several pages on how to do this and pretty much every one of them have this almost exact type of clamping so I'm not sure what I'm missing.