TLDR; there’s an infinite loop happening. As you are cloning the entity where the input is processed, as the clone gets added to the scene hierarchy, it’s update gets called and because it is in the same frame, the keypress is still considered as ‘wasPressed’, it clones itself again, etc forever.
So the solution is to move the logic for the cloning outside the entity you are cloning (ideally in a separate script where all the input can be processed separately from the entity’s logic).
It’s just handing a reference to the fireball entity that we are cloning. I’m just using Unity’s terminology to indicate that it is something that will be cloned. (Check the scenes Root entity for the usage of the input script).
just a small question. i want the shots to go in the direction the player faces, but when i think about it, the shots would turn around when the player turns around
As long as the shots are not children of the player entity, they will not be affected by the player changing direction unless you have code that explicitly does so.
If the camera is a moving camera, you can do world to screen to check if it is in view. It may not be the logic you want for the game though and may prefer them to be destroyed after a certain amount of time has passed.