I want to make a game object rotate until its Z axis it’s pointing towards a specific point. I have a variable named angle which is the angle between the object’s Z axis and the position of the point which it needs to point to. I have the following code right now:
while (angle > 0)
transform.Rotate (Vector3.right * rotationSpeed * Time.deltaTime);
transform.Rotate (Vector3.up * rotationSpeed * Time.deltaTime);
but it always ends up in an infinite loop and crashing because it just rotates by the amount I’m telling it to. So is there any way to tell the object to keep rotating until the angle is 0?