Unity 3.x Game Development by Example Beginner's Guide
上QQ阅读APP看书,第一时间看更新

Lick it and stick it

Return to Unity. You should still see your DisappearMe script in the Project panel. In order to attach it to the ball, drag-and-drop the file over the Ball Game Object in the Hierarchy panel. If drag-and-drop isn't your thing, you can also select the Ball Game Object, and choose Component | Scripts | Disappear Me from the menu. Once you do this, it may not look as if anything happened. To confirm that you did it correctly, click on the Ball. At the bottom of the Inspector panel where components of the Ball are listed, you should see your DisappearMe script.

Disappear Me!

Uncheck the Maximize on Play button in the Game view to experience the full effect of your script. (Cue circus music) And now, ladies and gentlemen, thrill to the astounding spectacle that you have created with a single line of code! Click on the Play button to test your game, and watch with amazement as your Ball disappears!

What just happened?

A good magician never reveals his tricks, but let's break down that piece of code we wrote to see what's going on behind the scenes.