Creating a Shooting Mechanic Using Raycasting in Unity
With the player moving around and aiming it is time to get them firing.
The first thing I did was add a reticule to the center of the screen. To do this I used a custom asset called Filebase created by GameDevHQ. From Filebase, I downloaded a reticule pack and chose the one I liked. I then created a UI image and added the reticule image to it.
To create the functionality for the shooting I created a new shooting script and attached it to the player.
The coding for this is fairly simple. If the player left-clicks you fire a ray from an origin point. You then collect the information about the object you hit. For now, I have the name of the object printing to the console.
This will allow the player to shoot from the middle of the screen.