I have four objects, each with box colliders, and a 3D Text Mesh. I am using this same script on all of them.
var powerlev = 0;
function OnMouseDown () {
if (powerlev == 1) {
LevelUp.mode = "Sleepy";
}
if (powerlev == 2) {
LevelUp.mode = "Brisk";
}
if (powerlev == 3) {
LevelUp.mode = "Rapid";
}
if (powerlev == 4) {
LevelUp.mode = "Insanity!!";
}
Application.LoadLevel ("BasicArea");
}
But only the last button will work. I’m setting the powerlev to its different numbers on the object in the editor. Why don’t the first three objects work? Thanks!
Just a remark: if you’re gonna pile “ifs” like that, use else in between each of them. This way if your value is 1, the first if is true, and you don’t evaluate all the other conditions thanks to the else.
Or, use a case, which is made exactly for what you’re doing (but the syntax is ugly).
That should make your code faster by about 0.000000000000001% ;), but hey, never hurts…