I use the code:
GameObject fire = (GameObject) GameObject.Instantiate(gameObject, transform.position, transform.rotation);
to create a clone of my bullet, and when I use it for the first time per scene, it works as expected, but on the second time it actually creates 3 clones, and on the third time it creates more clones than I can count.
Is there any solution?
EDIT: apperantly its pattern is:
When you use
Instantiate to create a clone, all of the scripts and components attached to the source object will be duplicated on the resulting clone. In this case, you’re cloning
gameObject, which means that the clone will also have a copy of this script that just made the clone.
Depending on how you run your logic, that means that your clones may also start spawning clones. Many beginners first run into this behavior when it creates an infinite loop and crashes their game.
So, generally speaking, you don’t want to clone yourself. Clone some other object like a prefab, instead.