Scripting in C# + Past 360 degrees

My apologies for not using the correct mathematical terminologies.

I’m trying to exceed rotation of an object past 360 degrees and under 0 degrees. I do not want degrees to resets to 0 and 360 degrees. I would like to use a float value that takes the current rotation and increments degrees past 360 degrees and under 0 degrees. In other words, I do not want the degrees to reset, ever! E.g. degrees could increment plus or minus 1460 degrees or more!

My program is a little complicated. But basically I am rotating a wheel that follows the position of when I click and drag. I want the wheel to stop at a specific rotation. I am doing this by setting a cap: if rotation is less then 360 degrees, set rotation to 360 and stop rotating. But when I drag my mouse past 360 degrees, the cap is broken and the wheel rotates past the break point.

I am thinking of it as a rope. If you twist a rope, there is no such thing as rotation resetting. The rope will rotate until it snaps. I want this kind of rotation; a rotation that does not reset.

How do I do this? What algorithm can I implement to achieve this in C#?

Okay I think I understand your question better now. Try adding this script to an empty gameobject in an empty scene and running it. Now, imagine a wheel or dial whose centre is the centre of the screen. Click on the wheel and drag it around the centre - clockwise to increase myValue, counter-clockwise to decrease myValue. myValue is capped at -450 and 4560.

using UnityEngine;
using System.Collections;

public class WheelRotation : MonoBehaviour {

	public float myValue = 0f; // This is the output value
	
	private float click;
	
	public float factor = 1f;
	// Change this to increase or decrease the wheel's effect on myValue
	

	void Update () {
		
		// hub of wheel is in centre of screen
		Vector2 hub = new Vector2( Screen.width/2f, Screen.height/2f );
		
		if (Input.GetMouseButton(0)) {
			
			// Get angle from hub to mouse position
			// (probably a better way to do this)
			Vector2 mousePos = Input.mousePosition;
			float mouseAngle = Vector2.Angle(Vector2.up, mousePos - hub);
			if (mousePos.x<hub.x) mouseAngle = 360f-mouseAngle;
			
			// If this is the click down, store the starting angle
			if (Input.GetMouseButtonDown(0)) {
				click = mouseAngle;
			}
			
			// How much has angle changed since last frame?
			float difference = mouseAngle - click;
			// To prevent error when going past zero
			if (difference>180f) difference-=360f;
			if (difference<-180f) difference+=360f;
			
			// Increment myValue by that difference and clamp it
			myValue += difference * factor;
			click = mouseAngle;
			myValue = Mathf.Clamp(myValue, -450f, 4560f);
			
		}
	
	}
	
}

I don’t know if I’m understanding your problem correctly. This script should cap the rotation properly, i.e. if myRotation < 0, wheel angle stays at 0, if myRotation is 0-360, wheel rotation is 0-360, and if myRotation >360, wheel angle stays at 360.

Using System;
Using UnityEngine;

public class CappedWheel : MonoBehaviour {
	
	public float myRotation = 0f;
	
	void Update() {
		
		transform.eulerAngles.x = Mathf.Clamp( myRotation, 0f, 360f );
		
	}
	
}

Or if I’ve understood it the wrong way round, this script will rotate the wheel ONLY when myRotation is outside 0…360:

Using System;
Using UnityEngine;

public class CappedWheel : MonoBehaviour {
	
	public float myRotation = 0f;
	
	void Update() {
		
		float x = (myRotation < 0f || myRotation > 360f) ? myRotation : 0f;
		transform.eulerAngles.x = x;
		
	}
	
}

The line in Update() is a shorter way of stating:

if (myRotation < 0f || myRotation > 360f) {
	
	transform.eulerAngles.x = myRotation;
	
}
else
{
	
	transform.eulerAngles.x = 0f;
	
}