UGTK cat mascotUGTKengine within an engine Request access

UGTK / Toolkit / Component Module / Shooting System Completed

Component Module — UGTK

Shooting System

Summary

The Shooting System is a comprehensive solution for managing shooting mechanics in games. It provides control over shooting actions, including handling ammunition, reloading, and projectile management. The system uses pooling to manage projectile spawning efficiently, ensuring optimal performance.


Content


Modules Dependencies

The Shooting System module requires the following dependencies:

Ensure that this dependency is correctly imported and configured in your project.


Setup

  1. Add ShooterComponent to your shooter object:

  1. Setup ShooterComponent info:

  1. Setup MunitionsComponent info:


How To Use

To use the Shooting System, use the following methods, called by code:

  1. Shoot Single Projectile::

  Vector3 direction = new Vector3(x, y, z);
  Mn_ShooterComponent.ShootSingleProjectile(direction, ignoreShootTimer);

  1. Shoot Multiple Projectiles:

  List<Vector3> directions = new List<Vector3> { direction1, direction2, ... };
  Mn_ShooterComponent.ShootMultipleProjectiles(directions);

  1. Enable Shooting:

  Mn_ShooterComponent.AbleShoot();

  1. Disable Shooting:

  Mn_ShooterComponent.DisableShoot();

  1. Add Munitions:

  Mn_MunitionsComponent.AddMunitions(int munitions);

  1. Set Infinite Munitions:

  Mn_MunitionsComponent.SetInfiniteMunitions(bool infinite);

  1. Set Maximum Munitions:

  Mn_MunitionsComponent.SetMaxMunitions(int max);

  1. Recharge Munitions:

  Mn_MunitionsComponent.Recharge();


Testing Scene

Open ShootingScene in the module's Scene/ folder. It holds a 2D shooter on the Canvas and a 3D one in the world; the demo camera frames the 2D pair.

What to do, in order:

  1. Enter Play Mode, select ShooterComponent and use Shoot (Configured Direction) in Runtime Tools. The magazine count above the buttons goes down by one per shot.
  2. Shoot until the magazine empties, then keep shooting. That is where onShootFail fires, which is what a reload prompt hangs off. Recharge Munitions fills it again.
  3. Use Shoot Multiple Projectiles, then compare with holding automatic shooting on.
  4. Detach the munitions component and shoot.

Step 4 shows the other branch: with no munitions component assigned the shooter fires forever, which is either exactly what you want for an enemy or a bug you will not notice for weeks.

On running out. A shot that finds no projectile in the pool is now a failed shot: it raises onShootFail and spends no ammunition. It used to raise onShootSuccess and take a round anyway, so the magazine emptied while nothing left the barrel. If you size the pool below the magazine, that is the behaviour you will meet.


Technical Info

Scripts:


© 2026 Marcello De Bonis. All rights reserved

Real dependenciesOpen in the map →

Measured from the repository: code references (asmdef) plus prefab and asset GUIDs. Importing this module alone brings in 11 modules in total.