Time for action – hook up the explosion

"But wait," you say. How do we actually tell the Script what we want to instantiate? Ah, there's the magic of Unity yet again. Save the Bomb Script, and follow these next steps:

  1. In the Project panel, select the Bomb Prefab.
  2. In the Inspector panel, find the Bomb (Script) Component. Notice that the variable we called prefab is listed there. (If you actually did call your variable "monkeybutt", you'll see that instead.)
  3. Click-and-drag the Explosion Prefab from the Project panel into the Prefab variable slot in the Inspector panel. You should see a little red green and blue icon appear in the slot, with the label Explosion Prefab. I've got a good feeling about this!

Test out your game. The bomb falls from the top ...

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.