- Home /
How to spawn enemies/objects that fly into a level
Hi,
I'm working on a game with a level made up of variously shaped tubes that constantly and randomly change direction as the Player moves forward. Some of the tubes have openings/holes in the ceiling and was wondering how I might go about/what the standard practice is for spawning enemies outside a level and have them fly into the play area. Enemies spawn areas are dependent on the tube used, as they all have different access points, etc. So the idea is to have a certain enemy spawn script kick in when (say, 'spawn and fly into roof') that tube is in use.
Any help, links to tutorials, etc. would be great :)
Answer by Berenger · Jun 24, 2012 at 03:36 PM
Either Instantiate, or use an instance pool. It's an object that holds several instances of your enemies, that can give you one when you need it and recycle those you don't need anymore. The point is to not use Destroy and Instantiate.
Hi Berenger, thanks for the reply.
I wonder if you might have some sample code to help me get an idea of what you mean? Yes, I've heard that using Destroy() can cause stutters and lag.
Your answer
![](https://koobas.hobune.stream/wayback/20220613073219im_/https://answers.unity.com/themes/thub/images/avi.jpg)