Instantiate spawn problem

Hey guys, I have a really strange problem. I need to spawn one object, after clicking on other object. I have 3 different objects, that spawns 3 different new objects, using this code:
135167-code.png
But when i click on one of these objects, it’s spawns all 3 objects. And when i click on a spawned objects, they are also spawns themselves. You can see the result of only one click:
135168-objects.png

I need a help. I want, when clicked, only one object spawns and that copies can not spawn themselves. Thanks for help

The reason the cloned objects are also cloning themselves is because they also clone this script that you posted. If you want to avoid this you have a couple options:

  1. Instantiate clones and disable the script component that is responsible for this:

    GameObject clone = Instantiate(Obj, new Vector3(0,0,0), Quaternion.Identity);
    ClickToSpawn script = clone.GetComponent();
    script.enabled = false;

  2. Make a prefab for the clones without the script and have the originals be an object with the script.