You may want to study your basic control flow structures and learn about scope. Also, using a float to rotate and an int to count the number of times you rotated would only work if your i was exactly 1, which is very unlikely.
Depending on where this code is and how you want things to be displayed, you probably don't even want a while loop. A while loop would just run through all your rotation in one go, without updating whatever you're rotating on screen in-between. Basically having:
float totalRotation = 0;
float rotationAmt = rotateSpeed * Time.deltaTime;
while(totalRotation < 90)
{
transform.Rotate(rotationAmt, 0, 0);
totalRotation += rotationAmt;
}
is the same (though less accurate) as :
transform.Rotate(90, 0, 0);
Likely what you really want, to have your object be updated on screen while it rotates is to store the objects current rotation somewhere and also store it's target rotation:
//stored in the object you're rotating
float rotation = 0;
float targetRotation = 0;
...
//inside our update for the object check the rotation to see if we're where we want to be
float rotationAmt = rotateSpeed * Time.deltaTime;
if(rotation!= targetRotation)
{
//first we check to see if there's just a small amount of rotation to shave off
// this check keeps us from never reaching the target rotation
if(abs(rotation-targetRotation) < rotationAmt) {
transform.Rotate(rotation-targetRotation, 0, 0);
rotation += rotation-targetRotation;
} else {
transform.Rotate(rotationAmt, 0, 0);
rotation += rotationAmt;
}
}
Now I know what you're going to do. You're going to copy and paste this code, and tell me it doesn't work. Don't do that. Just look at the code and see how it works. Then implement it yourself to fit your project. There are improvements that can be made to this code as well. Like checking which way to rotate to be fastest. Check this class to see how you might do that.
int xafter thewhileloop, which actually iterates overx? Have you declared anotherxvariable before? Please make sure that the pasted code is what you are actually running. – Dan Oct 3 '12 at 16:20