Unity-simple small game to control the ball (1)

Make a small game, use the keyboard arrow keys to control the movement of the ball, use the cube to enclose an area to prevent the ball from falling, control the ball to eat the small cubes, and eat one to score one point.

1c378b4b9102437a9c6a0331d417d545.png

 This is how the final game looks like.

14430b598c9b45f186a3ff7318430e10.png

This is what it looks like after running the game.

First add a ground, create a game ground in the "Hierarchy" window, right click and select "3DObject" - "Plane". (Remember to reset the coordinates of the ground)

Material

If you want to modify the ground color, you need to add a material to it. Create a new folder named Materials in the "Project" window to store materials, and create a new "Material" material file in the Materials folder. as the picture shows

d48f26730ce940569218d72d2e1c3f10.png

Drag the newly created material ball to the Ground in the "Hierarchy" window, and modify the color you like in the "Inspector" window.

f9a0334e6c1f4a70a6f5795849aeba6f.png

 Create Player

Create a Sphere, adjust an appropriate coordinate, and add a shader to it.

Rigidbody rigid body component

 Add gravity to the ball. Select the ball Player object in the "Hierarchy" window, click the "Add component" button on the smallest surface in the "Inspector" window, and add the "Rigidbody" rigid body component.

5776d484c198401baa0b07b88fd8babd.png

Add c# script file

To make the ball move, add a script file to the ball object.

Create a new folder Scripts in the "Project" window to store script files. Select the ball Player object in the "Hierarchy" window, click the "Add component" button at the bottom of the "Inspector" window, select "New Script", enter Player, and click "Creat and Add" to create a script file.

51200f7c9ae84748831fdf7ab616d31c.png

Guess you like

Origin blog.csdn.net/qq_64573579/article/details/127467079