# QUICK TIP - How To Make Gold Miner Game With Unity 2D

0 55,138
Related posts

Gold Miner game is a very popular game, the game belongs to the 2D game genre in the game you have to adjust the anchor to pull up as much gold as possible.

In this tutorial we will make a simple game screen in the game. This is the link of the apk demo file for Android: https://www.dropbox.com/s/zhc7bxgv9ubgc5k/miner.apk?dl=0

## Steps to make the game

• Create a unity2D project with name such as: minergame or whatever name you like!

Next we create a game screen named GamePlay In the game screen we add a sprite2D as the background image then adjust the scale of the image to make it full screen.

On the game screen we will have the following objects:

• The gold digger is a 2D image
• big and small pieces of gold, diamonds … are 2D images
• Two pieces of text to display the time and score. We will add the above images and text according to the interface as below.

Next we will create the anchor and the rope. We added a 2D sprite to make the string and added it the LineRenderer component. The anchor is a 2D sprite and is a child of the string.

To draw the idea wire, we will draw a line from the root of the rope to the anchor. In the script of the string we write the update function as follows so that the two ends of the rope are always at a root point and the other end is the position of the anchor.

In order for the anchor to oscillate like a pendulum, the idea is that the rope will rotate from -angleMax to angleMax, for example, the anchor will move because it is a child of the rope. In the script of the string we write the following function. speed is the speed of rotation and angleMax is the angle of rotation.

To touch the screen, the anchor moves in the direction of the anchor to the anchor we write the script for the anchor object as follows: we define velocity as the vector of the anchor’s direction.

After determining the velocity vector, apply it to the physical object of the anchor

If the anchor moves out of view of the camera, we move it backwards by reversing the velocity vector

The next step we will identify the collision between the anchor and the gold, diamonds. To do this we add those objects to the Boxcollider2D component

In the OnEnterCollider2D function of the gold or diamond objects we write (this is the function that captures the event when other collider objects touch it)

We consider whether the collision object is an anchor, then we change the direction of the anchor and reduce the towing speed.

At the same time we will let the gold move along the anchor. When pulled up, we remove it and add points.

To update the displayed point and time

Check if time runs out and end game

Above are the basic steps to make the game, to see details you can go to the link given above to the link and download the project to test run.

TinyURL for this post: https://tinyurl.com/y4wvkml2

Sorry, The Comment Form Is Temporarily Closed At This Time

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More

Language: