Previous: , Up: Combat   [Contents][Index]


6.9 Modern Gun

Component: ModernGun

Althoug originally developed for AK-47s and the like, this can be used for anything from a crossbow to a plasma rifle. It’s a multipurpose solution to get some decent FPS action going on. You will need to also set up a projectile prefab and some ammo handling using the included ’ClipInventory’ and related functionality. Clips are discarded on reload.

Pooling should only be used on mobile, to increase the stability of the game. It does this by delaying invocation of the garbage collector to clean up destroyed objects until the scene is unloaded.

Field of ModernGun: bool showAmmoGUI

Show how much ammo we currently have with a legacy Unity GUI? Not suitable for mobile devices.

Default value: true

Field of ModernGun: Rect guiArea

Normalized viewport rectangle representing the area used by the legacy GUI, values between 0 and 1

Default value: new Rect(0.01f, 0.9f, 0.2f, 0.09f)

Recommended Field of ModernGun: Texture2D crosshairs

A nice crosshair texture

Field of ModernGun: float crossSpreadScalar

How much to increase the size of the crosshairs when indicating spread

Default value: 1.0f

Input Settings

Field of ModernGun: bool useFireButton

Should we use Unity’s built-in input for fire button handling? If false, send ’Fire’ each frame.

Default value: true

Required Field of ModernGun: string fireButton

The button in the Input Manager associated with shooting things.

Default value: "Fire1"

Action Settings

Field of ModernGun: AimCorrectionTypes aimCorrection

What type of aim correction should we use? Raycast aims directly at what we point at, distant point aims at a point in the far distance representing our crosshair location (recommended for FPS games)

Default value: AimCorrectionTypes.None

Field of ModernGun: GameObject projectile

What do we spawn from the muzzle of the gun?

Field of ModernGun: bool poolProjectiles

Should the projectiles be added to a pool the first time they’re spawned so that they can be re-used from the pool later?

Default value: false

Field of ModernGun: float inheritVelocityScale

Multiplied by the velocity before it’s transferred to the projectile

Default value: 1f

Field of ModernGun: int magazineMax

How many shots per mag?

Default value: 32

Field of ModernGun: int magazineType

Which clip type from Clip Inventory do we use? First clip type is 0, second is 1, and so forth.

Default value: 0

Field of ModernGun: float reloadTime

How long does it take us to reload?

Default value: 2.2f

Field of ModernGun: GameObject muzzleTransform

A game object representing the exit point of the projectile

Field of ModernGun: float refireTime

How long, in seconds, between each bullet?

Default value: 0.4f

Field of ModernGun: float muzzleSpreadMin

Minimum variation of a bullet from center

Default value: .2f

Field of ModernGun: float muzzleSpreadMax

Maximum variation of a bullet from center

Default value: 2.0f

Field of ModernGun: float roundSpreadCost

How much the spread increases each time a projectile is discharged

Default value: .14f

Field of ModernGun: float refocusRate

How fast the spread decreases

Default value: .16f

Audio Settings

Recommended Field of ModernGun: AudioClip fireSound

’BANG!’

Recommended Field of ModernGun: AudioClip reloadSound

Sound made when reloading

Recommended Field of ModernGun: AudioClip ammoExhaustedClick

The worst sound you can hear in a firefight

Visual Settings

Recommended Field of ModernGun: GameObject image

The model of the weapon, if unassigned and no Animator found, no animations will be sent!

Recommended Field of ModernGun: GameObject muzzleFlash

An object spawned at the muzzle transform representing visual flash effects

Field of ModernGun: GameObject muzzleFlashSpawnTransform

An optionally different flash spawn transform

Field of ModernGun: float flashDuration

How long should the flash object be alive?

Default value: 0.125f

Recommended Field of ModernGun: string mecanimFireTrigger

A Mecanim trigger that will be sent to the Image

Recommended Field of ModernGun: string mecanimReloadTrigger

A Mecanim trigger that will be sent to the Image

Recommended Field of ModernGun: string mecanimAmmoExhaustedTrigger

A Mecanim trigger that will be sent to the Image

Message Senders

Field of ModernGun: MessageManager.ManagedMessage fireMessage

Message sent on successfully firing a round

Field of ModernGun: MessageManager.ManagedMessage reloadingMessage

Message sent when starting to reload

Field of ModernGun: MessageManager.ManagedMessage ammoExhaustedMessage

Message sent when we have run out of ammo

Available Messages

Message on ModernGun: Fire ()

Causes the ranged weapon to emit a projectile, respecting all firing rules.

Message on ModernGun: Reload ()

Initiates a reloading sequence for the weapon.

Field of ModernGun: bool showAmmoGUI

Show how much ammo we currently have with a legacy Unity GUI? Not suitable for mobile devices.

Default value: true

Field of ModernGun: Rect guiArea

Normalized viewport rectangle representing the area used by the legacy GUI, values between 0 and 1

Default value: new Rect(0.01f, 0.9f, 0.2f, 0.09f)

Recommended Field of ModernGun: Texture2D crosshairs

A nice crosshair texture

Field of ModernGun: float crossSpreadScalar

How much to increase the size of the crosshairs when indicating spread

Default value: 1.0f

Input Settings

Field of ModernGun: bool useFireButton

Should we use Unity’s built-in input for fire button handling? If false, send ’Fire’ each frame.

Default value: true

Required Field of ModernGun: string fireButton

The button in the Input Manager associated with shooting things.

Default value: "Fire1"

Action Settings

Field of ModernGun: AimCorrectionTypes aimCorrection

What type of aim correction should we use? Raycast aims directly at what we point at, distant point aims at a point in the far distance representing our crosshair location (recommended for FPS games)

Default value: AimCorrectionTypes.None

Field of ModernGun: GameObject projectile

What do we spawn from the muzzle of the gun?

Field of ModernGun: bool poolProjectiles

Should the projectiles be added to a pool the first time they’re spawned so that they can be re-used from the pool later?

Default value: false

Field of ModernGun: float inheritVelocityScale

Multiplied by the velocity before it’s transferred to the projectile

Default value: 1f

Field of ModernGun: int magazineMax

How many shots per mag?

Default value: 32

Field of ModernGun: int magazineType

Which clip type from Clip Inventory do we use? First clip type is 0, second is 1, and so forth.

Default value: 0

Field of ModernGun: float reloadTime

How long does it take us to reload?

Default value: 2.2f

Field of ModernGun: GameObject muzzleTransform

A game object representing the exit point of the projectile

Field of ModernGun: float refireTime

How long, in seconds, between each bullet?

Default value: 0.4f

Field of ModernGun: float muzzleSpreadMin

Minimum variation of a bullet from center

Default value: .2f

Field of ModernGun: float muzzleSpreadMax

Maximum variation of a bullet from center

Default value: 2.0f

Field of ModernGun: float roundSpreadCost

How much the spread increases each time a projectile is discharged

Default value: .14f

Field of ModernGun: float refocusRate

How fast the spread decreases

Default value: .16f

Audio Settings

Recommended Field of ModernGun: AudioClip fireSound

’BANG!’

Recommended Field of ModernGun: AudioClip reloadSound

Sound made when reloading

Recommended Field of ModernGun: AudioClip ammoExhaustedClick

The worst sound you can hear in a firefight

Visual Settings

Recommended Field of ModernGun: GameObject image

The model of the weapon, if unassigned and no Animator found, no animations will be sent!

Recommended Field of ModernGun: GameObject muzzleFlash

An object spawned at the muzzle transform representing visual flash effects

Field of ModernGun: GameObject muzzleFlashSpawnTransform

An optionally different flash spawn transform

Field of ModernGun: float flashDuration

How long should the flash object be alive?

Default value: 0.125f

Recommended Field of ModernGun: string mecanimFireTrigger

A Mecanim trigger that will be sent to the Image

Recommended Field of ModernGun: string mecanimReloadTrigger

A Mecanim trigger that will be sent to the Image

Recommended Field of ModernGun: string mecanimAmmoExhaustedTrigger

A Mecanim trigger that will be sent to the Image

Message Senders

Field of ModernGun: MessageManager.ManagedMessage fireMessage

Message sent on successfully firing a round

Field of ModernGun: MessageManager.ManagedMessage reloadingMessage

Message sent when starting to reload

Field of ModernGun: MessageManager.ManagedMessage ammoExhaustedMessage

Message sent when we have run out of ammo

Available Messages

Message on ModernGun: Fire ()

Causes the ranged weapon to emit a projectile, respecting all firing rules.

Message on ModernGun: Reload ()

Initiates a reloading sequence for the weapon.


Previous: , Up: Combat   [Contents][Index]