Hi, I’m trying to rotate the camera 90 degrees smoothly. However, when I do I either am off by a few decimal points, or it just keeps going and going. The code I am using is as follows:
function Rotate ()
{
//rotating = true;
var xRotation = 0F;
while (rota)
{
var deltaDegrees = rotateSpeed * Time.deltaTime;
Debug.Log(xRotation);
if (xRotation >= 90)
{
deltaDegrees = 90 - xRotation;
rota = false;
break;
}
else xRotation += deltaDegrees;
transform.Rotate(Vector3(0, 0-deltaDegrees, 0));
yield;
}
xRotation = 0F;
}
The problem is in the yield. If I turn it off, it just jumps to the position after a delay. If I leave it there it rotates slowly, and then quicker and quicker. Can I have some help? One more thing, the code that uses rotate is:
Rotate();
// Later in the code
if(!rota Input.GetKeyUp(KeyCode.LeftArrow))
{
rota = true;
}
All of this is in update();.