# Need help getting started on a spawn manager script.

So what I’m trying to do is make various projectile circles appear at different positions and moving in different directions for a 2D game where you just have to dodge the circles.

So do I just Random.Range to generate various values for the x and y then set that to a position variable which I use as a parameter for the Instantiate method? I’ve been trying to do this but I can’t really seem to figure it out. Also have no clue about the having them move part after spawned.

Pls help!

That’s it!

This gets into AI… plenty of tutorials on that.

If you want an endless series of balls spawning, this will happily fill your RAM up and eventually bog things down:

``````void Update()
{
float x = Random.Range( -5.0f, 5.0f);
float y = Random.Range( -5.0f, 5.0f);

GameObject ball = GameObject.CreatePrimitive( PrimitiveType.Sphere);
ball.transform.position = new Vector3( x, y, 0);
}
``````

Hmm… Thanks. Also I do know how to destroy game objects out of bounds so no need to worry about the RAM.

Again, so many ways:

• timed destruction (great for missiles)
• bounds check (great for endless runner enemies going off one side)
• count them and stop spawning when you reach a certain number
• contact with deadly stuff (lava or whatever)
• being shot by the player
• something else?

etc. etc. etc

Go and work through tons of different tutorials on spawning enemies and get a feel for what you’re dealing with. This is one of the biggest most open-ended areas of game design, so there is a lot of subtleties to grasp.

In my case its just the bounds check

Just posted this a few minutes back for keeping a pong racquet within bounds… same principle applies for killing off enemies, just using invisible GameObjects as your simple rectangular bounds:

https://discussions.unity.com/t/865111/2

Beyond that, look into trigger areas and surround your playfield with triggers that can be sensed and discerned to be deadly, and kill off enemies.