How to rotate object based on another rotation.

I am trying to create a tool in VR with a pointer where the user points and an object with the pointer then rotates their hand left and right which will in turn cause the item that they are pointing at to rotate on a set axis.

I have been working on code to do this but I always have great trouble when it comes to dealing with rotations.

The script I have been working on almost works bar 2 major issues.

Issue one: Quaternion loop issue. This issue arises when the quaternion has made a full turn. Instead of continuing to the next turn seamlessly the interactable item starts rotating in the opposite direction. I would like it to continue on its current direction of rotation and just move onto the next loop.

Issue two: Changing axis messes everything up. So most of my testing I was just working on the X axis because I believed if I got that working the other axis would work fine. However I found when switching axis from x to z for example the rotation would go completely haywire and not rotate any way I would expect it to have.

Any help or advice on this would be really appreciated I have been stuck on this one issue for 28 total hours now. I don’t think I’ve ever worked on anything that has held me up this long. A lot of the issues I’m having are probable down to me not fully understanding quaternions, but they are soooooo confusing.

Here is a pic of how i would like the rotations to work.

And a video link: - YouTube

And a link to the code: rot -

I don’t know how to create tools in VR. I coded it in plain Unity. At first I was thinking about some kind of mapping rotation of the hand into rotation of the target object, but I eventually gave up this idea. I decided to rotate both objects simultaneously and independently, which still gives the impression that the hand rotates the target.
So, I called my script and class Hand. Attach it to your hand object. Drag and drop the object you want to be rotated by your hand into target slot in the inspector. Now if you hold the left mouse button down and move the mouse left and right you will see that hand rotates only around X axis, while target rotates around axis which you set in the inspector. The target rotates always around one of its local axis, no matter if it is X, Y or Z. Check it out:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Hand : MonoBehaviour
	public Transform target;
	public enum Axis {X, Y, Z};
	public Axis axis;
	public float sensitivity = 100f;
	bool pressed;
	Vector3 vector3;
	void Update(){
		if (Input.GetMouseButtonDown(0)){
			pressed = true;
		} else if (Input.GetMouseButton(0) && pressed){
			float mouseX = -Input.GetAxis("Mouse X");
			transform.rotation *= 
				Quaternion.AngleAxis(mouseX * sensitivity * Time.deltaTime, Vector3.right);
			switch (axis){
				case Axis.X:
					vector3 = Vector3.right;
				case Axis.Y:
					vector3 = Vector3.up;
				case Axis.Z:
					vector3 = Vector3.forward;
			target.rotation *= 
				Quaternion.AngleAxis(mouseX * sensitivity * Time.deltaTime, vector3);
		} else if (Input.GetMouseButtonUp(0)){
			pressed = false;