Uniy3D Basics — Coroutines and Spawn Control

Claudio Grassi
5 min readApr 1, 2021

Coroutines are a special type of method that allows for the execution of code to happen intermittently. In contrast, a regular method in our scripts will run the code block inside of it in the span of one frame. This means that we have to create intricate systems if we want code to run over a length of time.

Unity defines Coroutines as:

A coroutine is like a function that has the ability to pause execution and return control to Unity but then to continue where it left off on the following frame.

Right now, we have our player and one enemy in the scene. Even by colliding with the player we essentially win the game. Congratulations, you can now sit back and wait for a major Studio to offer you a job!

GG EZ!

Not satisfied?! Neither am I…Let’s build something better!

OBJECTIVE:

Create an extendable method to spawn enemies periodically.

METHOD:

--

--

Claudio Grassi

Experienced digital artist, Unity game developer & coder with a knack for problem solving and a passion for video games.