I want to rotate my object to a specific angle smoothly and stop. I came up with the following code but it doesn’t seem to work. The code’s pretty simple but I can’t figure the problem.
public void move()
{
int i;
for (i = 0 ; i <= 10 ; i++) {
transform.Rotate(0, 0, i);
}
}
While you are only rotating 1° at a time, you are doing it in a for-loop which is executed sequentially, all of which happens between two frames. So still, all of your rotation happens ‘instantly’ as far as your game is concerned.
Update() is called each frame. So when your condition for rotating the object is met, you want to apply some portion of the rotation each frame, until your target rotation is met, then stop.
Alternatively you could look into doing this with a Coroutine.