HOW TO ADD AND MAKE AN OBJECT MOVE IN UNITY

 


Unity is the world's leading platform for creating and operating interactive, real-time 3D content, providing the tools to make amazing games and publish them to a wide range of devices.

In this blog, we will learn how to use the basics of unity specifically, adding an object and how to make it move.


1. OPEN UNITY. 

This is unity's main screen. We could see the Scene, Assets, Inspector, and Hierarchy windows. 


2. IMPORT ASSETS.

We need to import assets that we're going to use in our game. This may include music, pictures, or scripts. 

In this example, we're going to import ball png and brick png files we have downloaded. From the asset panel, right click and select Import New Assets... A pop up window will appear and select the assets you need. 





3. DRAG OBJECT IN THE SCENE PANEL.

To create a scene, drag objects in the scene panel. In this example, a ball on the left side with six stacked bricks above a platform in the right side.


4. ADD COMPONENTS TO ASSET.

Click the ball. In the inspector panel on the right, there is a button named ADD COMPONENT. Click it and search Rigidbody 2d and Circle Collider. The Rigidbody 2d will enable the ball to have a mass and volume to make it as an object or else it will just be a sticker or merely a picture in the game. The circle collider component will allow the ball to have a collider so when the ball hits another objects, it will collide.

We also need to set the Gravity Scale of the ball to 0 under Rigidbody 2d or else the ball will fall in the scene.

For the platform. add Rigidbody 2d and Box Collider. Gravity Scale 0.

For the box, we'll need Rigidbody 2d and Box Collider since the bricks are in a box shape. The bricks should have a Gravity Scale of 1 since we want the boxes to fall when hit by the ball.

Add Component Button on the Inspector Panel

Bricks

Platform

Ball

5. ADD SCRIPT.

Now we have added components in our assets, we'll now add the script for the ball to make it move. In the asset panel, right click and select Create, C# Script.

Name the C# Script according to its function. In our example, we named it Move. Click the ball, and add component, Move (the name of the script). Once the component is added to the ball, double click the script file in the Assets Panel to open Visual Studio.



6. ADD CODE FOR MOVE.

We'll be using keys (up), A (left), S (down)and D (right) to move the ball.



7. PLAY.

And we're done. To see how it will look like when played, click the play button on the upper middle center, and the game scene panel will appear. Play the game using the W, A, S, D keys.











Comments