onMouseDown button not properly working

Hey everyone,

In my scene I have a cube and a button that links to another scene(main menu).

The cube spins with this set of code:

void Update () {
		// Enter whilst the Left MouseButton is held down
		if(Input.GetMouseButton(0))
		{
			// Rotate over x, y and z with a speed between 0 and 40 * RotationSpeed
			// Warning: This will give some serious wacky rotating
			// You can get rid of some Axis if you want, turning them to 0, to not rotate over that Axis
			transform.Rotate(Random.Range(0,40) * Time.deltaTime * RotationSpeed,
			                 Random.Range(0,40) * Time.deltaTime * RotationSpeed,
			                 Random.Range(0,40) * Time.deltaTime * RotationSpeed);

The following script code is attached to my button:

public bool variable = false;


	void onMouseDown()
	{
		if(variable)
			Application.LoadLevel (0);
    }

Are the 2 scripts conflicting with each other? I made it so that the button has a box collider and is “on top of” the location of where the cube is so that I could click it. However, upon clicking, only the cube spins.

OnMouseDown, not onMouseDown.

Hello i’m detecting clicks with raycast.You can use this code at your first script.

 if (Input.GetMouseButtonDown (0)) {
    
    RaycastHit2D hit = Physics2D.Raycast (Camera.main.ScreenToWorldPoint (Input.mousePosition), Vector2.zero);
    
    	if (hit.collider == yourbuttoncollider&&variable) {

    		Application.LoadLevel (0);
    					
    	 }
    }