Getting Started

๐Ÿง  How It Works

A weapon is a few small components on one prefab:

  flowchart LR
    A[Weapon] -->|trigger| B(Barrel)
    B -->|asks for ammo| C(Magazine)
    B -->|shots| D[Hitbox and Health]
    B -->|events| E(Recoil, sounds, effects)
  • Weapon reads the trigger (its own input or your calls) and holds the barrel and the magazine.
  • Barrel decides how a shot travels: raycast, shotgun, projectile or laser. Its Config holds the fire rate, damage and bullets per shot.
  • Barrel modifiers change when the barrel fires: FiringMode (semi, burst, full auto) and Spool (wind-up and wind-down).
  • Magazine holds the ammo: a BulletMagazine that reloads or a RechargeableMagazine that refills over time. No magazine means infinite ammo.
  • Recoil listens to the barrel and kicks the weapon back.
  • Damage goes through the Modular Health System: every shot hurts the Hitbox it hits.

All scripts are in the GlowingRifts.ModularWeaponSystem namespace.

๐Ÿ“ฆ Installation

  1. Import the Modular Health System from the Asset Store. The weapon system needs it for health, hitboxes and damage.
  2. Import the Modular Weapon System. It’s installed under Assets/Glowing Rifts/Modular Weapon System.
  3. Make sure the Input System package and the Universal Render Pipeline are installed. The example materials and shaders are made for URP.
  4. Add the components from Add Component > Glowing Rifts > Modular Weapon. Laser Guide, Laser Follower and Mouse Follow are under Glowing Rifts > Misc.

๐Ÿ”ซ Ready-Made Weapons

The Weapons folder has five weapons you can drag straight into a scene. They only use files from the Weapons folder, so you can delete Examples and keep them.

PrefabHow it’s built
PistolRaycast barrel, semi automatic, bullet magazine, recoil
ShotgunDual weapon with a shotgun barrel, bullet magazine, recoil
GrenadeRifleDual weapon: a raycast barrel, plus a projectile barrel firing explosive grenades
RocketLauncherProjectile barrel firing rockets you can steer with a Laser Guide
LaserGunLaser barrel with a Spool wind-up and a rechargeable magazine

The building blocks (barrels, magazines, ammo, effects and an empty Weapon) are in Weapons/Prefabs.

๐Ÿงช Example Scenes

Open Examples/ModularWeaponSystem_Examples and pick an example. Press Escape in any example to come back. See Examples for each scene.

๐Ÿงฑ Your First Weapon

Add a Weapon

Add Weapon to the root of your weapon model. Turn on Use Built-In Input to fire with the mouse, or call StartShooting and StopShooting from your own input.

Add a Barrel

Add a barrel (for example Raycast Barrel) to a child of the weapon, and add a muzzle Transform to its Spawn Points, with the blue (Z) axis pointing forward. Set its Config: Fire Rate, Damage and Bullets Fired. Drag it into the Weapon’s Barrel field.

Add a Magazine

Add Bullet Magazine and drag it into the Weapon’s Magazine field. Leave the field empty for infinite ammo.

Hook the feedback

Use the barrel’s On Shot for the muzzle flash and sound, and its On Hit for impacts. Add Recoil above the barrel for kickback.

The Create Weapon guide builds the pistol step by step in the CreateWeapon scene.

Tip

Put targets on a layer the barrel’s Layers can hit, and give them a Health and Hitbox from the Modular Health System.