Skip to content
Adam Graham edited this page Jan 31, 2022 · 12 revisions

Links

FAQs


Where can I download the sprites?

The sprites are included the full project / source code which can be downloaded with this link: https://github.com/zigurous/unity-space-invaders-tutorial/archive/refs/heads/main.zip

Download and unzip the project, then look for the sprites in the Assets/Sprites folder.


Why not use colliders to detect when invaders hit the edge of the screen?

We could use colliders to detect when invaders hit the edge of the screen, but this solution would be more complex for two main reasons.

  1. The edge of the screen is going to be different depending on the player's screen resolution. This means we would need to write additional code to change the position of the colliders depending on the screen size. This code isn't too complicated, but it's still a bunch of excess code we can avoid.

  2. To check for collision with the colliders, we would use OnTriggerEnter2D. We could handle this as part of the Invaders.cs script or in the Invader.cs script. Either way, it'll require more complex code. For the former, you need to make sure the invaders' collider is always positioned and sized correctly to match the grid anytime an invader is killed. For the later, you would need to implement a design pattern to communicate from an individual invader to the group as a whole.

You might think using colliders prevents needing much code at all, and in most cases that's true, but for this particular use case it ends up require more code and code that is more complex. Although we took a manual approach of checking when invaders hit the edge of the screen using custom code, it ends up being a lot simpler.

Here is the relevant code for the solution used in the video: https://github.com/zigurous/unity-space-invaders-tutorial/blob/main/Assets/Scripts/Invaders.cs#L89-L114

Clone this wiki locally