官术网_书友最值得收藏!

Time for action – Make the ball bouncy

  1. Let's import a new package with certain goodies we'll need to make the ball bounce. In the menu, click on Assets | Import Package | Physic Materials, then click on the Import button. A bunch of Physic Materials (whatever they are) get added to our Project panel.
  2. Make sure that the Ball is selected.
  3. In the Inspector panel, find the Sphere Collider component of the Ball. If it is closed, click on the gray triangular arrow to expand it so that you can get at its goodies.
  4. Find the Material parameter of the Sphere Collider.
  5. Click on the small black circle next to the label that reads None (Physic Material).
  6. Choose Bouncy from the list.
  7. Test your game by clicking on the Play button.
  8. When you finally snap out of it, click on Play again to escape the mesmerizing results.

The Physic Materials package that we just imported includes a number of useful prebuilt physic materials. These special materials change what happens when a collider hits another collider. We chose the one called Bouncy, and lo and behold, when the Ball game object's Sphere Collider hits the Cube Collider of the Paddle, it reacts like a bouncy ball should. At our current phase of human technological progress, this is as close to a Make Game button as you're gonna get!

Have a go hero – DIY physic materials

Unity's Standard Assets package provided us with a Bouncy Physic Material to use, but we could just as easily have created our own. If you want to create your own Physic Material from scratch, right-click on a blank area of the Project panel, and then select Create | Physic Material. Alternatively, you can click-and-hold the mouse button on the Create button at the top of the Project panel and choose Physic Material.

A new Physic Material called (appropriately enough) New Physic Material appears in the Project panel. You can rename it the same way you renamed the Ball and Paddle game objects. Call it BouncyBall.

Click to select the Physic Material. Its parameters are listed in the Inspector panel. If you're desperate to know what everything does, click on the blue book icon with the question mark on it, and prepare to be bored to tears by talk of anisotropic friction. YAWN! What you really want to do is change the Bouncyness to 1, and set the Bounce Combine to Maximum. Or choose your own settings if you just want to see what they do.

Select the Ball again. Find where the Sphere Collider Component's Material parameter is set to that built-in Bouncy Physic Material, and then drag-and-drop your BouncyBall Physic Material into the slot where the built-in Bouncy one is. Alternatively, you can choose your BouncyBall Physic Material from the menu. The Bouncy Physic Material is swapped for your own custom-created BouncyBall Physic Material.

Tip

What a drag!

We'll be pulling that same drag-and-drop maneuver again and again as we use Unity. If you weren't feeling up to trying those last steps, don't worry; you'll get plenty of chances to drag stuff around the interface as we build more games.

Test the game by clicking on the Play button. The paddle is flat, the ball is bouncy, and everything seems right with the world! We haven't programmed any interactivity yet, but try moving and rotating the paddle around while the game is running using the Unity tools to get a sense of how the ball might react when we rig up mouse control in the next chapter. (You'll have to deselect Maximize on Play to gain access to your tools to try this out in the Scene view.)

主站蜘蛛池模板: 屯门区| 清苑县| 天全县| 建昌县| 莱州市| 北安市| 延吉市| 尉氏县| 福州市| 大石桥市| 平陆县| 互助| 两当县| 星座| 陆良县| 精河县| 武隆县| 景谷| 安陆市| 宜阳县| 繁峙县| 南漳县| 龙江县| 达州市| 临江市| 佛冈县| 扶绥县| 成安县| 星子县| 鄂伦春自治旗| 凌云县| 察隅县| 和林格尔县| 盐津县| 霍邱县| 栖霞市| 修武县| 化隆| 师宗县| 大姚县| 宜州市|