[Solved] Getting another enemy type to spawn

Hey, so I’ve actually finished this whole section, but this seemed the best place to put this. Once I’ve got this working I think I’ll be done! So I want to put in a second enemy type. I want keep things simple and get it to spawn when I kill the first enemy type, and vice versa. So I created another enemy prefab and attached it to my EnemySpawner script. For best context here’s the script:

I went back through the relevant lectures and put in the code needed for the second enemy type. In the game it spawns and behaves exactly as expected. The only problem is getting the first and second enemy types to spawn after each other. The bit to focus on is the AllDead method. Not even sure if this is the best way to do it but it seems the most logical to me! Anyway, what happens is the first enemy type spawns… first, then when they’re destroyed the second enemy type spawns, but from then on, when they’re destroyed, it’s only the second enemy type that spawns and the first doesn’t spawn anymore.

Also, as you can see, I put an “Invoke” in an attempt to get it to repeat. The problem here is that I get a CS1501 error that says: “No overload for method ‘Invoke’ takes ‘1’ arguments”. I would of course like help with that as well but first I want to get the spawn order fixed.

Hope that all makes sense!

1 Like

Hello @James27 how are you?

The error happens because invoke only takes 1 argument (only the string corresponding to the name of the method), it don’t takes a input for the spawn delay (invokerepeat has an delay option).
To make the expected behave you will need to create an int counter that gets incremented by one each time it runs AllDead() method, and make an if statement with if counter <=1, calls the method to instantiate the enemy1, else it calls the method yo instantiate enemy2

1 Like

Hey, @Joao_Dalvi thanks for replying!

Got it working! Finally!

2 Likes

Good! I’m glad to know!

1 Like

Privacy & Terms