Spawning different enemy types

Rusben Guzman
Sep 2, 2021

Objective: Modify the spawn manager to spawn randomly different enemy types

The first step is to declare a gameobject array to save the different enemy prefabs.

Then we have to go to the Unity editor and assign the prefabs in the inspector.

In the spawn manager I created a function to generate an int related to each enemy type. The function receives an int as a parameter, with different if conditions we check the value of the variable and return another int associated with the enemy type.

In the spawn enemy coroutine I declared an int variable called enemy type and assigned the result of the get enemy index function result and when l called the instantiate function I passed the enemy array with the generated enemy index as a parameter.

And that’s it!!! We can spawn different enemy types.

--

--

Rusben Guzman

A Software Engineer passionate about game dev and interactive products with Unity. I consider video games to be the artistic expression of programming.