Ok, so I’m trying to rotate my object, while a certain variable is not equal to another variable, this is the script I got.
private var go : boolean = true;
private var angle : float;
private var currAngleY : float;
function Update () {
if(Input.GetKeyDown("a")) {
rotate("left");
}
}
function rotate(direction : String) {
Debug.Log("rotating");
if(direction == "left") {
if(go) {
currAngleY = transform.eulerAngles.y - 90;
go = false;
}
while(currAngleY <= transform.eulerAngles.y) {
angle = Mathf.MoveTowardsAngle(transform.eulerAngles.y, currAngleY, 20 * Time.deltaTime);
transform.eulerAngles = Vector3(0, angle, 0);
}
}
}
As soon as I try to run this, Unity just freezes and I have to hardreset it. Is there a way to make my object turn smoothly for only 90 degrees each time and then make it stop until the next input is given.