The Instantiate() function is instantiating the clone.

I am trying to instantiate one instance of the prefab “Cube” whenever I click the right mouse button. But the problem is my code instantiates the clone of the prefab, which creates the clone of the clone and so on. I wanted the instance of prefab only and one at a click. Please help me through this. Thank You!

ps : Please tell me if i’m not clear. Because I’m new in this community.

You shouldn’t attach the script to the prefab you’re instantiating. First of all the prefab would reference itself in the “spawner” variable. That means after instantiation spawner will reference the instance since any self references are adjusted when instantiated.

Second since you have that script on each instance you create whenever you click the mouse button every of those script instances will create a new clone of themselfs. So if you have one object in the scene you get just another one. If you click again each of the two objects you have now will create a new clone. So you have 4 then 8, 16 ,32, …

You should create an empty gameobject in the scene and attach your script to that object. Assign your cube prefab to the spawner variable of that object. Make sure you remove your script from the actual cube prefab.