How to force camera rotation?

Very simple here, I know… But I think I’m lost.

I’ve coded a script to control my camera and here is what I do to handle mouse control:

void LateUpdate() {
	
	if (camlock == false) {
		_x += Input.GetAxis("Mouse X") * xSpeed * 0.02f;
		_y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f;
		
		Quaternion rotation = Quaternion.Euler(_y, _x, 0);
		
		_myTransform.rotation = rotation;
	}
}

It works pretty fine. But when player will press a button I’d like to force the camera position and orientation. I’ve tried using:

	transform.rotation = Quaternion.LookRotation(my_new_rotation_vector3);

But the rotation is not good (due to the lateUpdate method computing _x and _y according to Input.GetAxis() I think).

Any idea on how I should do to force camera rotation? should I use quaternions? If yes how?

Thank you.

This will modify the current camera rotation by the mouse, allowing you to set another rotation. Drop your _x and _y variables.

 void LateUpdate() {

    if (camlock == false) {
       var rot = transform.rotation.eulerAngles;
       rot.x += Input.GetAxis("Mouse X") * xSpeed * 0.02f;
       rot.y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f;

       _myTransform.rotation = Quaternion.Euler(rot);
    }

}