CATCH THE CRAB

 


In this blog, we will try to create a simple point and shoot game. We will be needing the following assets:


First, place the crosshair and player in the main game scene. Design the game according to your choice. Since we will use the crab as our enemy, we will use a beach background.


Make a script and copy the code below. In this example, we named the script PointAndShoot. Add this as a script component of the Main Camera.


For creating the projectile/bullet prefab, drag the asset to the scene panel. Add Rigidbody2D and Circle Collider 2D as a component. Drag it back to the asset panel and you'll see the prefab of the projectile is created. The left crab is the regular asset, the right crab is the prefab asset. Do the same for the web/bullet asset.


Create an empty scene and name it as PlayerHolder. Make the player as a child and add another empty scene named bulletStart.


Place the bulletStart just right into the player canon. This is where the web/bullet will come from. 


Now, assign the gameObjects in the Main Camera Script. Drag the assets or manually select it in the Inspector Panel.


For the enemy, we will need these script. I named it as CrabSpawn.


We'll need another script for its movement. The code is as follows:


Add the Movement Script to the Crab Prefab. Create another empty scene in the Scene Panel. Name it as CrabSpawning. Add the CrabSpawn Script here and assign the values as shown below.


And lastly, we'll need a CrabDestroy Script. Copy the code and add it as a component of the Web Prefab.


See there is a tag labeled Enemy. We will select the Crab Prefab and find in the Inspector Panel the Tag. Create a tag and name it as you like. In my example, I created a Tag and named it enemy. This will enable the web to destroy the crab.



And, we're done. The game looks like this:











Comments