all objects sharing script get destroyed?

So I have a script that spawns an object, the object waits for a bit and destroys itself. I also wanted the functionality to click on the object, and have it destroy itself.

If I just have one, it works beautifully.

If I have more then one of these “spawners” running, and just let them wait out their lives, they each die at their unique wait time.

However, if I click on one to destroy it, all of them get destroyed?

#pragma strict

var Countdown:		int 	= 	5;
var visible: 		float 	= 	0.50;
var invisible:		float 	= 	0.50;
var blinkFor: 		float	= 	5.0;
var startState: 	boolean =	true;
var endState: 		boolean =	true;
var rayDistance: 	float 	= 	0;

function Start () 
{
	animation.Play ();
	transform.position.z = -5;
    renderer.enabled = startState;
    yield WaitForSeconds(Countdown);
    
    var whenAreWeDone = Time.time + blinkFor;
    
    while (Time.time < whenAreWeDone)
    {
        if ( startState )
        {
        	renderer.enabled = false;
            yield WaitForSeconds(invisible);
            renderer.enabled = true;
            yield WaitForSeconds(visible);
        } 
        else
        {
            renderer.enabled = true;
            yield WaitForSeconds(visible);
            renderer.enabled = false;
            yield WaitForSeconds(invisible);
        }
    }
    renderer.enabled = endState;
    Destroy ( gameObject );
}

function Update ()
{
	if (Input.GetMouseButtonDown(0))
	{
  		var hit :RaycastHit;
  		var ray :Ray = Camera.main.ScreenPointToRay(Input.mousePosition);  			// get mouse position
  
  		if (Physics.Raycast (ray, hit, rayDistance))
  		{
  			if (hit.transform.tag == "resource")
  			{
  				Destroy ( gameObject );	
   			}
   		}
	}
}

Thanks in advance for any help you can offer.

I guess because all of them have the tag “resource”. You should check if this is the clicked object or destroy the object which was hit.

(code not tested)

if (hit.gameObject.Equals(gameObject))
{
    Destroy(gameObject);
}

or

if (hit.transform.tag == "resource")
{
    Destroy ( hit.gameObject );
}

Add one more condition like-

if (hit.transform.tag == "resource" && hit.gameObject == gameObject)
{
            Destroy ( gameObject );   
}

Here is code:

 //Destroy object on click
 var hit : RaycastHit;
   			var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
   			
   				if ( Physics.Raycast ( ray, hit, 100 ))  {
     					 if ( hit.collider.gameObject.renderer && Input.GetMouseButtonUp(0)){
        						 //When user click left mouse button -select block-
        						 Debug.Log(hit.collider.gameObject);

And here is destroy part:

Destroy (hit.collider.gameobject);

Hope it works!~