Top Down Shooter Blueprint Code [Unity3D 4.3]


Game Jam coming up and you don’t want to waste time programming the basics of a top down shooter game? If your using Unity, then this code may be for you! I have set up the basic structure for a top down shooter game for you to use for your game development needs. I have tried to make the code easy to expand upon and easy to understand.

Features that are in the game are as follows:

  • Raycasted projectiles
  • Reloading
  • Ammunition pickup (can easily be used for many other item pickups as well)
  • Weapon Switching – 2 weapon inventory
  • Aiming/Scope

The Game Development Environment


Raycasted Projectiles
The Raycast will give the distance of the object that is hit from the player shooting. It will also give feedback of specified objects that are hit. Right now the detection is setup to detect when a Player object is hit, this can be changed by changing the mask layer used for detection. Additionally, theere

Reloading will discard the current ammo in the clip loaded in the weapon, and will load a new full clip in the weapon. The pistol is currently setup to hold 2 clips in reserve, while having 1 loaded. To reload the weapon the key, “1”, is to be used. This can be changed under Edit->Project Settings->Input, and then under the heading Reload1.

Ammunition Pickup
This allows the player to be able to pickup the ammo clips if they have enough room to do so. This code can be modified to allow multiple different item pickups. Just add another if(pickup.CompareTag(XXX”), and by replacing XXX with your new game object’s tag, you will now be able to pickup that new object.

Weapon Switching
The player can hold 2 weapons that they can switch between. This code could have been changed to be more modular to allow different types of switching in a more friendly manner; however, I’m sure it wouldn’t take to long to do so. By pressing “Q”, the player will select the weapon in slot 1, while pressing “E”, the player will select the weapon in slot 2. This can be changed under Edit->Project Settings->Input, and then under the heading Weapon_1 and Weapon_2.

There are 2 different distances the player can shoot at, which can also be set different for different weapons. One distance is the un-aimed distance, this is the shorter range for the weapon  and does not have any line of sight to help the player aim. The other distance is the aimed distance; by pressing and holding the Command key (or Windows equivalent key) a range indicator will show up and will increase the range the player can shoot objects at.


Range indicator when pressing the aiming key.

Hope you enjoy this code and if you decide to make a game using this code please post your project in the comment section below so everyone can see!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s