O'Reilly logo

Unity 3D Game Development by Example by Ryan Henson Creighton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required