how to clamp y axis with Quaternion.Euler in unity

void Rotate()
{
Vector3 lastDirectionInGlobal = _camera.ScreenPointToRay(rightFingerLastPoint).direction;
Vector3 currentDirectionInGlobal = _camera.ScreenPointToRay(rightFingerCurrentPoint).direction;

	Quaternion rotation = Quaternion.identity;
	rotation.SetFromToRotation(lastDirectionInGlobal, currentDirectionInGlobal);
	
	ownTransform.rotation = ownTransform.rotation * Quaternion.Euler(0, kInverse ? rotation.eulerAngles.y : -rotation.eulerAngles.y, 0);



	rotation.SetFromToRotation(	cameraTransform.InverseTransformDirection(lastDirectionInGlobal),
	                           cameraTransform.InverseTransformDirection(currentDirectionInGlobal));

	cameraTransform.localRotation = Quaternion.Euler(kInverse ? rotation.eulerAngles.x : -rotation.eulerAngles.x, 0, 0) * cameraTransform.localRotation;

	rotation =   Quaternion.Euler(Mathf.Clamp (rotation.eulerAngles.x, -80, 80),Mathf.Clamp (rotation.eulerAngles.y, -80, 80), 0);//using mathclamp for rotation limit on x  &  y

	rightFingerLastPoint = rightFingerCurrentPoint;

	rotation = Quaternion.Euler(cameraTransform.rotation.eulerAngles.x, cameraTransform.rotation.eulerAngles.y, 0);

	cameraTransform.rotation = rotation;

}

I have done clamping for x axis (-80,80) degree which is working fine, but y axis showing no clamping on (-80,80) degree . Am i doing something wrong. please help me.

There is way too much code here. The “rotation” variable seems to be used for about six different things. In particular, you’re applying clamping when you assign rotation on line 13, but then on line 17 (before you’ve used that clamp rotation for anything!), you reassign rotation to something completely different, with no clamping.

So, that’s why the clamping doesn’t work… I can’t make out what your code is intended to do, but if you simplify it and remove the pointless lines (like line 13), I think you’ll be able to fix it.