[2Ed] Chapter 30: Prototype 3: Space Shmup

The SHMUP (or shoot ’em up) game genre includes such classic games as Galaga and Galaxian from the 1980s and the modern masterpiece Ikaruga.

In this chapter, you create a SHMUP using several programming techniques that will serve you well throughout your programming and prototyping careers, including class inheritance, enums, static fields and methods, and the singleton pattern. Though you’ve seen many of these techniques before, they will be used more extensively in this prototype.

Typo causes Enemy to disppear after 1 frame

  • This doesn’t always happen, but a tiny typo in the book on page 563 will cause Enemy GameObjects to sometimes disappear after one frame. On page 563, under step #3, on the line marked //d, there is a negative sign missing. The corrected line should look like:

        if (pos.y < -bndCheck.camHeight - bndCheck.radius) {    // d

  • Also note that you must later delete this line of code as part of the revisions to this update method in step 4 of pages 565-566. The entirety of this update method after the changes in step 4 should be:

        void Update() {
            Move();
            if ( bndCheck != null && bndCheck.offDown ) {
                // We're off the bottom, so destroy this GameObject
                Destroy( gameObject );
            }
        }

Unity 2018.2.2 – Camera.main Bug

  • In Unity 2018.2.2, sometimes when creating a Camera, the tag of the Camera is set to “Untagged” instead of “MainCamera”. As a result, any references to Camera.main will cause Null Reference Exceptions.
  • To remedy this, all you need to do is set the tag of the Main Camera to MainCamera.

 

Starter Package

Tutorial Files