Chapter 29: Prototype 2: Mission Demolition

Physics games are some of the most popular around, making games like Angry Birds household names. In this chapter, you make your own physics game that is inspired by Angry Birds and all the physics games, such as the board game Crossbows and Catapults, that came before it.

This chapter covers the following: physics, collision, mouse interaction, levels, and game state management.

Typo on page 542 – Causes ProjectileLine to not appear

  • On p.542, the code as written in the book sets projectile = null; before then assigning it to ProjectileLine.S.poi. This causes the ProjectileLine to never have a projectile assigned to it.
  • To fix this, just move the line projectile=null; to the end of that if statement. The code in the book should look like this:


public class Slingshot : MonoBehaviour {
    …
    void Update() {
        …
        if (Input.GetMouseButtonUp(0))
        {
            // The mouse has been released
            …
            FollowCam.POI = projectile;
            MissionDemolition.ShotFired();                // a
            ProjectileLine.S.poi = projectile;            // b

            projectile = null;              // THIS LINE MOVED
        }
    }
}

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.

 

Lecture Notes

 

Tutorial Files