Destroying gameObject destroys all objects

I would like to destroy a gameObject in my scene after so conditions are met, this works but it also destroys the other objects that have the same script even though their conditions have not met yet, hopefully the code explains it a bit:

using UnityEngine;
using System.Collections;
public class selectObject : MonoBehaviour 
{

	public bool isSelected = false;

	public GameObject[] prefab;

	public string ballColor = "";

	void Update () 
	{

		if (Input.GetMouseButtonDown (0))
		{
			RaycastHit hitInfo = new RaycastHit ();
			bool hit = Physics.Raycast (Camera.main.ScreenPointToRay(Input.mousePosition), out hitInfo);

			if (Input.GetMouseButtonDown (0) && hit) 
			{
				Debug.Log("Hit " + hitInfo.transform.gameObject.name);
				if (hitInfo.transform.gameObject.tag == "redBall")
				{
					isSelected = true;
					ballColor = "red";
				}

				else if(hitInfo.transform.gameObject.tag == "blueBall")
				{
					isSelected = true;
					ballColor = "blue";
				}
				else if(hitInfo.transform.gameObject.tag == "greenBall")
				{
					isSelected = true;
					ballColor = "green";
				}
				else if(hitInfo.transform.gameObject.tag == "yellowBall")
				{
					isSelected = true;
					ballColor = "yellow";
				}


				if(isSelected == true && ballColor == "blue")
				{
					if (hitInfo.transform.gameObject.tag == "bCapsule")
					{
                            //It gets here but i only want the blue ball destroyed, it destroys all balls in the scene right now
    						Debug.Log ("I'm here");
    						Destroy (gameObject);
    					
    				}
    
    			}
    		}
    	}
    
    }

Hi,

Thats really easy problem The thing is you are Destroying the gameObject on which the script resides instead of destroying the one that is hit by the ray

public GameObject SelectedBall ; // Made it public so that you could see wether its is working or not

 void Update () 
    {
 
        if (Input.GetMouseButtonDown (0))
        {
            RaycastHit hitInfo = new RaycastHit ();
            bool hit = Physics.Raycast (Camera.main.ScreenPointToRay(Input.mousePosition), out hitInfo);
 
            if (Input.GetMouseButtonDown (0) && hit) 
            {
                Debug.Log("Hit " + hitInfo.transform.gameObject.name);
                if (hitInfo.transform.gameObject.tag == "redBall")
                {

                    isSelected = true;
                    ballColor = "red";
                   SelectedBall = hitInfo.transform.gameObject;
                }
 
                else if(hitInfo.transform.gameObject.tag == "blueBall")
                {
                    isSelected = true;
                    ballColor = "blue";
 SelectedBall = hitInfo.transform.gameObject;
                }
                else if(hitInfo.transform.gameObject.tag == "greenBall")
                {
                    isSelected = true;
                    ballColor = "green";
 SelectedBall = hitInfo.transform.gameObject;
                }
                else if(hitInfo.transform.gameObject.tag == "yellowBall")
                {
                    isSelected = true;
                    ballColor = "yellow";
 SelectedBall = hitInfo.transform.gameObject;
                }
 
 
                if(isSelected == true && ballColor == "blue")
                {
                    if (hitInfo.transform.gameObject.tag == "bCapsule")
                    {
// Here the object (ball) is destroyed only if the object has name blue
                            Debug.Log ("I'm here");
                            Destroy (SelectedBall);
 
                    } // Similarlry
                    
                }
            }
        }
 
    }

Destroy(gameObject) destroys the object on which this script resides

so use
Destroy(hitinfo.transform.gameobject)

Edit The Object should contain either of the tags above inorder for them to be destroyed

As a quick fix, try replacing:

Destroy (gameObject);

with:

Destroy (hitInfo.transform.gameObject);