Hi there, I have an hexagon and I want to press a key and rotate it Smoothly by 60 degrees over the Z axis in order to have one of its faces aligned with the horizon, press the key again and rotate another 60 degrees, and so on by 60 degrees to the left/right.

I’m trying a few things but I can’t get it to work properly I can make it work perhaps once or twice but it’s kind of unstable, can anyone tell me please the best way to do this?

Here is the code I’m using but can’t say if it is much of a help.

```
void Update()
{
if (Input.GetKey(KeyCode.LeftArrow))
{
left = true;
}
if (left)
{
StartCoroutine(TurnLeft());
}
if (Input.GetKey(KeyCode.RightArrow))
{
right = true;
}
if (right)
{
StartCoroutine(TurnRight());
}
}
public IEnumerator TurnRight()
{
rotation = 60;
Quaternion to = Quaternion.Euler(0, 0, rotation);
transform.rotation = Quaternion.Lerp(transform.rotation, to, Time.deltaTime * 3f);
yield return new WaitForSeconds(2f);
transform.rotation = to;
right = false;
yield return null;
}
public IEnumerator TurnLeft()
{
Vector3 eulerAngles = transform.eulerAngles;
if (eulerAngles.z >= 0 && eulerAngles.z <= 60)
{
rotation = 60;
transform.eulerAngles = eulerAngles;
}
else if (eulerAngles.z >= 60 && eulerAngles.z <= 120)
{
rotation = 120;
transform.eulerAngles = eulerAngles;
}
Quaternion to = Quaternion.Euler(0, 0, rotation);
transform.rotation = Quaternion.Lerp(transform.rotation, to, Time.deltaTime * 3f);
yield return new WaitForSeconds(2f);
transform.rotation = to;
left = false;
yield return null;
}
private static float WrapAngle(float angle)
{
angle %= 360;
if (angle > 180)
return angle - 360;
return angle;
}
private static float UnwrapAngle(float angle)
{
if (angle >= 0)
return angle;
angle = -angle % 360;
return 360 - angle;
}
```