Communication between elements

I have public integers assigned to different elements. I want to choose 2 by clicking mouse and compare it in function.

void Compare(int A, int B)
{
     if(A >B)
     DoSomething;
     else
     DoNothing;
}
`
Should I use void OnMouseUp()?
`

Aassigned = defined a public integer variable in class of the element.
The Elments are game object with collider.
They should be compared as siin as you selected the second game object.

I failed with the title choosing, what I meant is rather picking GameObjects.
This is what I have, but I want if function to work when mouse cursor is on the GameObject. Can you help me with that?

void Update () {
	
		if(Input.GetMouseButtonDown(0))
		{
				Debug.Log ("Click 1");
		}
		if (Input.GetMouseButtonUp (0)) 
		{

			NextA = otherGameObject.GetComponent<SecondScript>();
			a = a- NextA.a;
			Debug.Log ("Click2"+a);
		}
	}