In this blog, I am going to share my ways how did I created a Shooting and Pointing Player Gameplay using Unity 2D. Among other activities, the usage of components are getting much wider from hereon.
Now we are going to need to create objects such as a player, enemy, game map, bullet, turret, and crosshair. We can produce these objects using Adobe AI. Let's drag and drop our object in project>Assets.
Then let's drop these Objects into our Scene, First, the Crosshair and Turret along I created Script called pointandshoot, and then I applied it to the Main Camera.
PointandShoot Script
Here we apply Crosshair Object as my mouse cursor
After that, I need to create Gameobject so that our turret will move as intended, set its position to "0" put inside the turret as a child, then the same applies to our turret base. Then we drag bullet prefab into our Screen and apply component "RigidBody2D" then set Drag & Gravity to "0" and "BoxCollider2D" set trigger, and drag back again it into our Project Asset Tab. Then we delete it in the Scene.
Next, in my Turret Parent, we created another empty object called "BulletStart" so the bullet will come out and not disperse around the turret. Position it within the tip of the turret
Then put it set the player to Turretholder and bullet Prefab in our MainCamera Script
I also created a Script for bullet optional if you want to have a scoring you can refer to my previous blog(act 4).
Bullet Components
Now I applied Turret Station where I will add another script called playermovement (previous code)that will allow us to move using the "WASD" key. And then make it as the parent of our turretHolder.
Station Properties
Then I add the battlefield map and 3 plane targets. Let's make sure that they will appear on the scene by adjust their Z position in Inspector.
Airplane Targets Components
Hierarchy of the objects
Lastly, I created Script for targets so whenever we shoot them down they will explode for a certain amount of bullet hit them. We apply the script to the airplanes as they are our targets.
Enemy Script
Actual Scene
Gameplay
For Clearer Explanation you can watch this tutorial
Point and Shoot: https://youtu.be/7-8nE9_FwWs
Explosion : https://youtu.be/WgLd6EahyVU