Nerd For Tech
Published in

Nerd For Tech

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.




NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit

Recommended from Medium

Serverless number crunching

Pointers in Depth

File Structure | Digital Forensics

How I Taught Myself to Code - Week 7

Introduction to Error Correcting Codes

Case Study: Automated global deployments on AWS with HIPAA Best Practices


Utah Lawyers

utah lawyers

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Matthew Clark

Matthew Clark

Unity Game Developer and C# Programmer

More from Medium

This can be Your Template for a Main-Menu Scene in Unity

How to make better UIs with Unity 9-slicing sprites

Indy Pro ’22: Distance System

Initializing A Git Repository in Unity