Destroy an instance of a prefab

Hello, i wrote the following script for the fireworks prefab in my game:

var fireWorksID : int; //This Prefab unique Id to determine which fireworks effect is used!
var speedFactor : float = 10.0;	
var secondLimit : float = 4.0; 



 var target : GameObject;	
 var gameManager : GameObject;
 var gameManagerScript : GameManager;
private var speed : float;
 var timer : float; 
private var hit : RaycastHit;
private var ray : Ray;


function Start () {
	
	target = GameObject.FindWithTag("target");
	gameManager = GameObject.FindGameObjectWithTag("GameManager");
	gameManagerScript = gameManager.GetComponent("GameManager");
	transform.LookAt(target.transform.position);
	
}


function FixedUpdate () {

    if(Input.touchCount == 1) {
        ray = Camera.main.ScreenPointToRay(Input.touches[0].position);
        Debug.DrawLine(ray.origin,ray.direction * 10);
        if(Physics.Raycast(ray.origin, ray.direction * 10,hit)){
            Explode(1);

        }
    }
}

function Update () {

	timer += Time.deltaTime; //Count in seconds

	speed = speedFactor * Time.deltaTime;//this may go in update!

	
	transform.Translate(0, 0, speed);

	if (timer >= secondLimit) {//Time-Out
		Explode(0); //Call Explosion by time out (status = 0)
	}
}


function Explode (status : int){
	
	if (status == 1){//detonated
		
			//Call DetonateFirewors() function on game manager with this object's id, status and position
		//gameManagerScript.DetonateFireworks(fireWorksID,transform.position,1);
		
		}
	else if (status == 0){//timed out

			//Call DetonateFirewors() function on game manager with this object's id, status and position
		//gameManagerScript.DetonateFireworks(fireWorksID,transform.position,0);
		
		
		}
	else {
		
			//This one should not be called, but just in case it may be managed as a miss or maybe just "neutral"
		//gameManagerScript.DetonateFireworks(fireWorksID,transform.position,0);
					
		Debug.Log("Somehow you managed to make a mistake!");
		}
		
		Destroy(this.gameObject);
		print("Was destroyed!?");

}						

My problem is that when in play mode i touch the prefab all the active clones are destroyed too, i want to destroy only the one i touched, however when they “timeout” they actually destroy only themselves…
I hope you can help me , thanks :slight_smile:

In your FixedUpdate() code you are casting a ray and asking did I hit AN Object. If the answer is yes, then you explode. I think what you want to do is cast a ray and ask did I hit ME and if yes, then Explode.

It also seems to me that you are performing input processing for each instance of the GameObject …

I can’t help but feel that it would be better to have a separate (empty) Game Object to own your input processing so that the input processing is done just once. In THAT input processing, you would cast the Ray once and then if it hit an object, you would ask THAT object to explode as opposed to having all objects do input processing and ask if THEY should explode.