Accumulative rotational value

I am working on a game mechanic for a wheel that when turned, gives the value of the localEulerAngles and stores into the variable currentNum

currentNum = myWheelMain.transform.localEulerAngles.y;

The issue that is a problem has to do with the fact that I am rotating the wheel by using an aim constraint, and it resets the localEulerAngles after reaching 360, so my resulting value can only is only 0-360, as opposed to an actual angle that is cumulative.

I have made an attempt at taking the current value and subtracting the prev value before the current value changed, but I haven’t got that to work just yet.

Here’s how I’ve approached that…

 currentNum = myWheelMain.transform.localEulerAngles.y;

        difNum = (currentNum - prevNum);

        if (difNum != 0.0f)
        {
            prevNum = currentNum;
            difNum = 0.0f;
        }

        finalNum += difNum;

Euler angles can jump all over the place as an object rotates and are not a good way to solve this issue. Instead find the delta rotation each frame and grab the angle from that.

Quaternion prevRot;
float finalNum = 0;

Start(){
    prevRot = myWheelMain.transform.localRotation;
}

Update(){
    //This returns the quaternion rotation between this frame and the last frame
    Quaternion fromPrevToCurrent = Quaternion.Inverse(prevRot) * myWheelMain.transform.localRotation;

    finalNum += fromPrevToCurrent.eulerAngles.y;

    prevRot = myWheelMain.transform.localRotation;
}

Thank you for this… I’m thinking I’m on the right track, but I do still have a small issue.

As long as the result for the next value is positive, this solution seems to be working. In other words if I rotate the wheel clockwise.

How would I go about subtracting the value if the wheel rotates the opposite direction, or counter-clockwise?