[solved ]While loop freezing?

every time I run:

function Update () {
//Thing1
    var Thing1 = Random.Range(1,5);
 
 
//turret2
    var Thing2 = Random.Range(1,5);
 
while (Thing2 == Thing){
    Random.Range(1,5);
     }
Debug.Log ("Thing1: " + Thing1 +     "Thing2: " + Thing2); 
}

unity freezes. I read that unity freezes from infinite loops. But I cant find why this is infinite? can anyone help?

Also if your feeling generous please check out my other question at: Destroying and not destroying (Not Solved) - Unity Engine - Unity Discussions

Inside your while loop you do not assign the random value to Thing2 or Thing1, so if they are the same, you will endlessly call Random.Range() and discard the results.

1 Like

… I feel dumb. Thanks haha :slight_smile: noob questions +1

No problem. Programmer for 35 years now and I think it has only been a day or so since I’ve made an error exactly like this.

Welcome to programming, the final frontier.

2 Likes