Time for action – fire!

In order to have something for the ship to fire, we have to create a variable at the top of the script called bullet, and then click-and-drag the Bullet Prefab into the variable slot in the Inspector panel. Otherwise, the script will have no idea what we're talking about when we try to instantiate something called bullet.

Follow these steps:

  1. Add the variable declaration at the top of the HeroShip Script:
    var bullet:GameObject;
    
  2. Save the script.
  3. In the Hierarchy panel, select the HeroShip Prefab.
  4. In the Inspector panel, find the HeroShip Script component.
  5. Hook up the Bullet Prefab to the bullet variable.
    Time for action – fire!

Let's add a few lines of ...

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.