OnMouseDown not working..

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!

A doubt it’s the mouseup per se? Have you checked and double checked any differences between the objects?

Yes, they’re EXACTLY the same except for the text in their Text Mesh and the powerlevel variable.

  • Anything in the way?
  • Are you setting timescale?

O_o whoops. There was another collider on an invisible object in front of those ones. Thanks for trying to help anyways! n_n

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…