Time for action – code do-si-do

Because the needs of our game have changed, we might reconsider how and where our code is written. In The Break-Up, it made sense for the player character to detect all collisions. But in Shoot the Moon, all the significant collisions actually happen on the enemy ship. The enemy ship has to know when it hits the hero ship, and it needs to know when it hits a bullet. So we can actually localize all of the collision code on the enemy ship. This makes a lot of sense, so let's make that change by transplanting some code:

  1. In the HeroShip Script, delete the OnCollisionEnter function.
  2. Delete the explosion variable declaration from the top of the script.
  3. Save the HeroShip Script.

    As we did with the ResetPosition() function, ...

Get Unity 4.x Game Development by Example Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.