Smooth transition from 360 to 0 degrees

Hello, I have a wheel which rotates by 45 degree on Button press. My problem is that if I am on 315 degree
It instead of rotating +45 degree to 360 it rotates -315 degree back to 0. How can I fix this or make 360 equal to 0? Any help is appreciated.

Greetings from Switzerland.

snow2405

112309-bildschirmfoto-2018-03-03-um-133239.png

if (rotating)  //This is in Update
		{
			Vector3 to = new Vector3(0, 0, AngleofEveryColor[Cubecolor]); // Array with 45 degree steps 
			if (Vector3.Distance(ColorCirle.eulerAngles, to) > 0.5f) // stops lerping if distance is less than 0.5 degree
			{
				ColorCirle.eulerAngles = Vector3.Lerp(ColorCirle.rotation.eulerAngles, to, Time.deltaTime*10.0f);
			}
			else
			{
				ColorCirle.eulerAngles = to;
				//rotating = false; // deactivated for testing
			}
		}

I would use Quaternions. Euler angles are responsible for this weird behaviour. Try my code. You can adjust the angle and axis of rotation in this line:

Quaternion target = transform.rotation * Quaternion.AngleAxis(-45f, Vector3.forward);

Here’s my code:

private bool rotating;

private void Update()
{
	if (Input.GetMouseButtonDown(0) && !rotating)
	{
		StartCoroutine(RotateMe(1f));
	}
}

private IEnumerator RotateMe(float duration)
{
	rotating = true;
	float t = 0f;
	Quaternion target = transform.rotation * Quaternion.AngleAxis(-45f, Vector3.forward);
	while (t < 1f)
	{
		t += Time.deltaTime / duration;
		transform.rotation = Quaternion.Lerp(transform.rotation, target, t);
		yield return null;
	}
	rotating = false;
}