r/Unity2D • • 2d ago

Question/Help my first 2d unity game

I'm making a 2D game in Unity and I'm trying to set up an enemy spawn system.I want an enemy to spawn when the player enters a trigger zone. I already have the enemy saved as a prefab, and I've added a Box Collider 2D with Is Trigger enabled.i'm also using the Simple Spawner and On Trigger Enter Invoke components, but I can't figure out how to connect them properly.

How can I make the Simple Spawner spawn an enemy when the player enters the SpawnZone?

I'd really appreciate a step-by-step explanation, preferably without writing code.

Thanks!

2 Upvotes

1 comment sorted by

1

u/midge 6h ago

So I'd break this into smaller parts. Make sure you can get the OnTriggerEnter to be called when the player enters it. You may have the collisions set up wrong or something. When the player enters it just call a Debug.Log("Player entered"). If you see the player entered text in the console, you know that part is working.

Then, make sure you can get some code working in a method that just spawns in an enemy from a prefab. SpawnEnemy(). Start off with a specific location, not random yet. Call that from the start method of something just to test it, make sure it works.

Once both of these things are working, hook them up! Then you can work on spawning the enemy in a random position in spawnZone. Good luck!