Why does this crash Unity? Ammo goes from 12 down to 0 when the loop stops so there is no need to crash.
using UnityEngine; using System.Collections;
public class TestScript : MonoBehaviour {
public bool MouseClick = true;
public int Ammo = 12;
void Start(){
while (MouseClick = true) {
Ammo = Ammo - 1;
if(Ammo <= 0){
MouseClick = false;
}else{
print ("Bang");
}
}
print("Empty");
}
}
Comment
Answer by Barsonax · Nov 01, 2015 at 07:57 PM
Change the = to == here: while (MouseClick = true)
From what i know = means you are setting something to something and == compares something to something. I tested this and with == it does not crash.
No problem please set this question to answered if this was what you were looking for :)