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:
In the Project panel, select the Bomb Prefab.
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.)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 of the building, "hits" the ground, and calls in the Explosion Prefab before popping back up to the top of the building at some random X
position. The Explosion, because of its DestroyParticleSystem Script, does its thing and then disappears from...