leg7075
leg7075

Reputation: 3

Unity freezes because of script, but i don't know whats wrong with said script

Bear with me, I'm pretty new to unity. As the title suggests, the game engine freezes when this script is attached to the main camera.

public class leftright : MonoBehaviour {
    public float boundaries = 3f;

    void Update () {
        while (Input.GetAxis("Mouse X") < boundaries && Input.GetAxis ("Mouse X") > -boundaries) {
            this.transform.Rotate(0, Input.GetAxis("Mouse X"), 0);
        }
    }
}

I don't think this script makes an infinite loop, and I can't detect any problem with it.

the log text is here, and the project is here

Upvotes: 0

Views: 148

Answers (1)

While(true) {
    //do stuff
}

The conditional you're using in your while statement cannot (and will not) ever change from true to false based on the contents of the loop, therefor it will run forever.

Update() is already a loop, treat it like one.

void Update () {
    if(Input.GetAxis("Mouse X") < boundaries && Input.GetAxis ("Mouse X") > -boundaries) {
        this.transform.Rotate(0, Input.GetAxis("Mouse X"), 0);
    }
}

Upvotes: 2

Related Questions