When I destroy a prefab instance the game destroys all instances.

Hello, I’m making a game of exploding balloons, but when I explote one, all of them explodes. Here is the code for exploding the balloons :

void Update()
{
//for destroying the balloons
if(Input.GetMouseButtonDown(0)){
Destroy(gameObject);
}
}

Here is the code for creating the instances. The script is in an empty game object called scripter, so don’t say the problem is that. Here is the code:

public GameObject BalloonPrefab;
float timer;

// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{
timer += Time.deltaTime;

if(timer >= 2f){
timer = 0;
float x = Random.Range(-2.5f, 2.5f);
Vector3 position= new Vector3(x, -6.5f, 0);
Quaternion rotation = new Quaternion();
Instantiate(BalloonPrefab, position, rotation);
}
}

hi, by any chance did you assign this script to all balloons? If so, the problem is easy to fix. The problem is that when you press the mouse button each script will activate and destroy the balloon it is assigned to.
To fix this you can use a script that destroys the balloon if you click on it

if (Input.GetMouseButtonDown (0))
{
         RaycastHit hit;
         Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         if(Physics.Raycast (ray, hit))
         {
//p.s you must assign a "Balloon" tag to all balloons else you can name all the balloons with the name Balloon and change hit.transform.tag with hit.transform.name
          if(hit.transform.tag == "Balloon")
          {
            Destroy(hit.collider.gameObject);
          }
        }
  }

if you are doing a 2D game you can use a Raycast2D instead like this:

if (Input.GetMouseButtonDown(0))
 {
    Vector3 MousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
    Vector2 MousePosition2D = new Vector2(MousePosition.x, MousePosition.y);

    RaycastHit2D hit = Physics2D.Raycast(MousePosition2D, Vector2.zero);
     if(hit.transform.tag == "Balloon")
     {
         Destroy(hit.collider.gameObject);
     }
}

Sorry for my bad english :sweat_smile: