Enemy Spawning

I just want to spawn enemy automatically when the game run so I did this simple basic concept but its working without the spawn time function without spawn time enemy spawned on a given position but its spawned unlimited so I add time to it and if condition but after that when I run the game enemy not spawning. what is the problem?
Here my script.1

It is spawning the enemy on the given position I just figure out where my problem was but another problem raised after spawn time end and it equals the 0 and enemy game object spawned after that if I see in my hierarchy 100 of 1000 enemies spawning simultaneously and my game got stuck and I have to forcefully shut down my editor.

I want to spawn one enemy and then after given time one enemy and so on.


Please note, it’s better to copy/paste your code and apply the code fencing characters, rather than using screenshots. Screenshots are ideal for displaying specific details from within a game engine editor or even error messages, but for code, they tend to be less readable, especially on mobile devices which can require extensive zooming and scrolling.

You also prevent those that may offer to help you the ability to copy/paste part of your code back to you with suggestions and/or corrections, meaning that they would need to type a potentially lengthy response. You will often find that people are more likely to respond to your questions if you make it as easy as possible for them to do so.

Did you try to implement a timer? If so, do not spawnTime to a specific value but subtract Time.deltaTime. And if the if-block gets executed, you could set spawnTime back to 2f.

Hope this helps :slight_smile:

See also;

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms