Chapter 5 confusing code tips for GameController.cs

If you follow the steps through Chapter 5 - page 121-125 on spawning enemies in GameController.cs it gets VERY confusing. Even if you follow it exactly to the letter as laid out in the book your code will be wrong.

The reason is that it’s never clear where you add code - ie - which IF or WHILE loop you are supposed to be in - the only way to get it perfect is to compare your code to the final examples.

Because there are a total of 6 nested loops in the GameController, here is an extremely helpful tip for newbies - turn on “Indent Guides” in the MonoDevelop Editor. I’m sure PC is similar, but to do this on Mac:

MonoDevelop-Unity → Preferences
under Text Editor → Markers and Rulers
check the box next to “Show indentation guides”

This allows you to visually see where each nested loop starts and ends. Yes you can click on the { or } to see this as well but it’s nowhere near as helpful. Try it if you are totally confused reading the loops.

2 Likes