How to add an object or obstacle to make it move, create a simple game in unity
In this blog, I will share with you step by step how I develop a unity basic game as part of our activity in CS Elective 2 Class which is a Game Development subject.
First of all, we must first create a new project, select 2d then you can name it whatever you want and we can continue.
After that select your newly created project, Unity game development interface will pop up. In this interface, this is our working area where lots of buttons and terminologies of components are not familiar to me.
Next, Here I created our necessary object for our game like the ball, platform, and the brick using Adobe Illustrator. You can see in the picture that it is already there, simply we can just drag and drop our PNG Pictures inside the Asset tab.
Now we can start, Put the ball inside our scene, at the right of the asset tab we can see the Game tab which is the actual output of our design. Going back to the ball, click it, at the far right we can see the properties and its characteristics, and down below there is the add component button.
Select the Add Component button, search for Rigidbody 2d & Circle collider 2D and add them, which will enable the physics of the ball having a movement and collision sensor. Change the gravity scale to 0 in Rigidbody 2d so it will not move on its own.
The RigidBody 2D

The Circle Collider 2D

Next is we create a box frame using our plank from the asset, just copy-paste the single plank to recreate and position them each side of the frame. Meanwhile, let's add Rigidbody 2d and Box Collider 2d to each of them.
We change nothing in our box collider but we will the Rigidbody 2d so the object frame remains from its position. For that, we need to check all of the boxes inside of constraints (X, Y, Z).
Then let us add another plank where our brick will stand. Apply the same method the way we did to the box frame, get the Rigidbody 2d, then check all boxes in constraints and Box Collider 2d from the components.
After that place the brick on the platform in the middle. We can duplicate the single box to form a pyramid (5 bricks). After that, each of them must have Rigidbody 2d and Box Collider 2d. We will just need to change the gravity scale to 2 and Collision Detection from discrete to continue.
And for the last part of our development, we need to create a scripting file that will allow us to control the ball using WASD keys. Just select the ball on our scene, proceed to add components, Select new script then type the name of the script lastly, click select and add. After doing that you will see the script file in the assets together with our png pictures.
Open that scripting file and we type this code using visual studio code.
Viola, this is our finished product.
PS. In case encountering that some variables in unity are not recognized by the suggestion library. I'd like to give you this fix if you encounter it. Go to Unity, Edit > Preferences, Select External Script Editor: Visual Studio Community. This will fix your problem.

No comments:
Post a Comment