Script detecting which object was clicked

Hello guys,

I have this problem.
In my scene I have 20 objects, each with a script with a separate name that basically does the same thing. What it does, is that when the object is clicked, the script attached to it draws with NGUI a certain button.

The problem is that it draws the button for any clicked object, instead of the object which passes the conditions.

The script :

public class BattleCheck1 : MonoBehaviour {
	
	public GameObject labelAttack;
	public GameObject labelChallenge;
	private int attack1;
	private int challenge1;

	// Use this for initialization
	void Start () {
	
		NGUITools.SetActive(labelAttack.gameObject,false);
		NGUITools.SetActive(labelChallenge.gameObject,false);
		
		attack1 = PlayerPrefs.GetInt("attack1");
		challenge1 = PlayerPrefs.GetInt("challenge1");
		
	}
	
	// Update is called once per frame
	void Update () {
		
		if(MapMenu.checkChallenge == true)
		{
			if(attack1 == 1)
			{
				NGUITools.SetActive(labelAttack.gameObject,true);	
			}
			
			if(challenge1 == 1)
			{
				NGUITools.SetActive(labelChallenge.gameObject,true);	
			}	
		}
	
	}

The other objects have the scripts with variables attack2,3,4… and challenge2,3,4 etc.
For now I have only the attack1 = 1 and the rest of the variables are set to 0, but the button is drawn each time I click on any object.

How can I fix this?

Thank you

Why not raycast from the camera at the mouse cursor position and then gather information based on what the raycast hit? That’s how I handle all this manner of stuff. That way you can switch off data already on that gameObject (tags, layers, gameObject.name, or any attached script).