![]() |
2DShooterWeaponSystem
1.9.0
|
The meat of the asset, the WeaponSystem component is used to hold weapon configurations, and bullet pattern setups as well as handling the logic for firing the bullets and setting bullet properties up based on the configuration. More...
Public Types | |
enum | BulletOption { BulletOption.Spherical, BulletOption.TracerHorizontal, BulletOption.TurretHorizontal, BulletOption.Beam1, BulletOption.Beam2, BulletOption.Beam3, BulletOption.Beam4, BulletOption.Beam5, BulletOption.Beam6 } |
The different bullet options available. More... | |
enum | ShooterType { ShooterType.Horizonal, ShooterType.Vertical, ShooterType.FreeAim, ShooterType.TargetTracking, ShooterType.HorizontalFaceLeft, ShooterType.VerticalFaceDown } |
Allows the user to adjust the direction which the bullets/weapons fire. More... | |
enum | BulletPresetType { BulletPresetType.CrazySpreadPingPong, BulletPresetType.GatlingGun, BulletPresetType.Simple, BulletPresetType.Shotgun, BulletPresetType.WildFire, BulletPresetType.ThreeShotSpread, BulletPresetType.DualSpread, BulletPresetType.ImbaCannon, BulletPresetType.Shower, BulletPresetType.DualAlternating, BulletPresetType.DualMachineGun, BulletPresetType.Tarantula, BulletPresetType.CircleSpray } |
Default weapon presets. More... | |
Public Member Functions | |
delegate void | BulletPresetChangeHandler () |
delegate void | WeaponConfigurationChangedHandler (Transform gunPointTransform, int weaponConfigIndex) |
delegate void | ReloadStartedHandler () |
delegate void | ReloadFinishedHandler () |
delegate void | WeaponShootingStartedHandler () |
delegate void | WeaponShootingFinishedHandler () |
void | EquipWeaponConfiguration (int slot) |
From version 1.3 onward, you can setup weapon "configurations" which are stored in the weaponConfigs List property. More... | |
IEnumerator | LoadMagazine (bool instantReload, bool useReloadSfx) |
Reload magazine coroutine - used for reloading weapon configurations from remaining ammo pool. More... | |
IEnumerator | LoadMagazine (bool instantReload, bool useReloadSfx, int amountToReloadWith) |
Reload magazine coroutine - used for reloading weapon configurations with a certain number of bullets instead of a full clip. More... | |
Public Attributes | |
string | weaponName |
The name assigned to the weapon configuration that is currently equipped. More... | |
float | bulletSpread |
The spread that bullets will use for their pattern (when more than one bullet) More... | |
float | bulletSpreadPingPongMax |
The maximum spread to bounce up to when ping pong spread is enabled. More... | |
float | bulletSpreadPingPongMin |
The minimum spread to bounce down to when ping pong spread is enabled. More... | |
float | spreadPingPongSpeed = 1f |
The speed at which the bullet spread is bounced between. More... | |
float | bulletSpacing |
The spacing between bullets when using more than one bullet. More... | |
int | bulletCount |
The number of bullets to fire. More... | |
float | bulletRandomness |
An amount of randomness to add to bullets when firing them (adds jitter to bullet streams / patterns). More... | |
float | bulletSpeed |
Speed at which bullets travel More... | |
float | weaponFireRate |
float | weaponXOffset |
Offset on the X to position the start of a bullet when fired from a 'gunPoint' transform. More... | |
float | weaponYOffset |
Offset on the Y to position the start of a bullet when fired from a 'gunPoint' transform. More... | |
float | ricochetChancePercent |
The chance a bullet fired from this weapon will have to bounce / ricochet off other colliders. More... | |
float | magazineChangeDelay |
The time it takes to reload / change a magazine. More... | |
int | magazineSize |
The number of bullets in a magazine. More... | |
int | startingAmmo |
The starting ammo for a weapon configuration. More... | |
int | ammoUsed |
Amount of ammo used in a weapon configuration thus far. More... | |
int | magazineRemainingBullets |
Remaining bullets in the weapon configuration's magazine. More... | |
Transform | targetToTrack |
The target for the weapon to track in 'Turret Track' mode. More... | |
float | trackingTurnRate |
The rate at which a weapon in 'Turret Track' mode will turn to face it's designated target. More... | |
bool | lerpTurnRate |
If enabled, then the turn rate of a weapon system in 'Turret Track' mode whilst tracking its assigned target will be eased (instead of the weapon always instantly facing it's target). More... | |
Color | bulletColour = Color.white |
If you are using plain white sprites this color value can be used to dynamically change bullet color in-game. More... | |
Texture2D | weaponIcon |
The texture2D assigned to a weapon configuration - can be used for GUI display of selected weapon for example. More... | |
bool | autoFire |
Enable this to automatically fire without need for input (useful for enemies etc) More... | |
bool | pingPongSpread |
Enable to bounce the spread value of bullets between the pingpong spread min and max values (causes bullet pattern to 'swing' up and down). More... | |
bool | circularFireMode |
When enabled, this will rotate the gun point transform around 360 degrees at a constant rate, allowing you to form circular bullet patterns. More... | |
float | circularFireRotationRate = 240f |
The rotations per minute that the gunPoint transform will rotate with, if circularFireMode is enabled. More... | |
bool | richochetsEnabled |
Enable if bullets fired from the weapon should allow ricochets (based on percent chance for bullets to ricochet). More... | |
bool | hitEffectEnabled |
Enable if bullets from this weapon should spawn hit effects (like sparks for example) when impacting colliders. More... | |
bool | limitedAmmo |
Enabled if the weapon configuration has limited ammo. More... | |
bool | usesMagazines |
Enabled if the weapon is configured to have ammo and use magazines. More... | |
bool | isFirstEquip |
Used to track if a weapon configuration is the first equip or not. More... | |
bool | playReloadingSfx |
Allow the playback of the reloading SFX when reloading. More... | |
bool | playEmptySfx |
If enabled, then the empty SFX is played when attempting to shoot with an empty clip. More... | |
bool | weaponRelativeToComponent |
If enabled, the aiming/facing direction is calculated relative to the transform that the WeaponSystem component is placed on. More... | |
bool | mirrorX |
Duplicates the number of bullets being used and mirrors the extra bullets on the X-axis More... | |
bool | bulletCountsAsAmmo |
If enabled, then every single bullet coming out will count toward ammo usage if limitedAmmo is enabled. More... | |
float | aimAngle |
The aim angle the weapon system is currently at in radians. More... | |
AudioClip | reloadSfxClip |
The reload SFX clip for the selected weapon configuration More... | |
AudioClip | emptySfxClip |
The empty magazine SFX clip for the selected weapon configuration More... | |
AudioClip | shotFiredClip |
The shot fired SFX clip for the selected weapon configuration More... | |
Transform | gunPoint |
The gun point or transform location that bullets are shot / generated from when shooting. More... | |
BulletOption | bulletOptionType |
ShooterType | shooterDirectionType |
Properties | |
BulletPresetType | BulletPreset [get, set] |
(Legacy - pre version 1.3, but still usable) This property dictates what weapon is selected for the WeaponSystem. More... | |
List< WeaponSystemConfiguration > | weaponConfigs [get, set] |
The list of weapon configurations on this Weapon System. More... | |
Events | |
BulletPresetChangeHandler | BulletPresetChanged |
Event that fires when a bullet preset is changed. More... | |
WeaponConfigurationChangedHandler | WeaponConfigurationChanged |
Event that fires when a Weapon Configuration is changed (weapon changed). More... | |
ReloadStartedHandler | ReloadStarted |
Event that fires when reloading starts. More... | |
ReloadFinishedHandler | ReloadFinished |
Event that fires when reloading finishes. More... | |
WeaponShootingStartedHandler | WeaponShootingStarted |
Event that fires when shooting starts. More... | |
WeaponShootingFinishedHandler | WeaponShootingFinished |
Event that fires when shooting stops. More... | |
The meat of the asset, the WeaponSystem component is used to hold weapon configurations, and bullet pattern setups as well as handling the logic for firing the bullets and setting bullet properties up based on the configuration.
|
strong |
The different bullet options available.
This will be used to select the bullet type pulled from the Object Pool Manager. You can change the bullets here by adding different or custom bullet prefabs to the ObjectPoolManager instance in your scene that map to each of these enum options.
Enumerator | |
---|---|
Spherical | |
TracerHorizontal | |
TurretHorizontal | |
Beam1 | |
Beam2 | |
Beam3 | |
Beam4 | |
Beam5 | |
Beam6 |
|
strong |
Default weapon presets.
Feel free to add new ones here! Just don't forget to handle the new bullet presets in the BulletPresetChangedHandler method that is fired with the BulletPresetChanged event.
Enumerator | |
---|---|
CrazySpreadPingPong | |
GatlingGun | |
Simple | |
Shotgun | |
WildFire | |
ThreeShotSpread | |
DualSpread | |
ImbaCannon | |
Shower | |
DualAlternating | |
DualMachineGun | |
Tarantula | |
CircleSpray |
|
strong |
delegate void WeaponSystem.BulletPresetChangeHandler | ( | ) |
void WeaponSystem.EquipWeaponConfiguration | ( | int | slot | ) |
From version 1.3 onward, you can setup weapon "configurations" which are stored in the weaponConfigs List property.
You should use this EquipWeaponConfiguration method to change weapons, passing in the index of the list for the weapon you want to select. Use the in-editor inspector on the WeaponSystem component to setup new configurations and add them to the inventory/configurations list.
slot | The weapon configuration 'slot' index to equip. |
IEnumerator WeaponSystem.LoadMagazine | ( | bool | instantReload, |
bool | useReloadSfx | ||
) |
Reload magazine coroutine - used for reloading weapon configurations from remaining ammo pool.
instantReload | |
useReloadSfx |
IEnumerator WeaponSystem.LoadMagazine | ( | bool | instantReload, |
bool | useReloadSfx, | ||
int | amountToReloadWith | ||
) |
Reload magazine coroutine - used for reloading weapon configurations with a certain number of bullets instead of a full clip.
This might be useful if you wish to have the player reload one bullet at a time for example.
instantReload | |
useReloadSfx | |
amountToReloadWith |
delegate void WeaponSystem.ReloadFinishedHandler | ( | ) |
delegate void WeaponSystem.ReloadStartedHandler | ( | ) |
delegate void WeaponSystem.WeaponConfigurationChangedHandler | ( | Transform | gunPointTransform, |
int | weaponConfigIndex | ||
) |
delegate void WeaponSystem.WeaponShootingFinishedHandler | ( | ) |
delegate void WeaponSystem.WeaponShootingStartedHandler | ( | ) |
float WeaponSystem.aimAngle |
The aim angle the weapon system is currently at in radians.
int WeaponSystem.ammoUsed |
Amount of ammo used in a weapon configuration thus far.
bool WeaponSystem.autoFire |
Enable this to automatically fire without need for input (useful for enemies etc)
Color WeaponSystem.bulletColour = Color.white |
If you are using plain white sprites this color value can be used to dynamically change bullet color in-game.
int WeaponSystem.bulletCount |
The number of bullets to fire.
bool WeaponSystem.bulletCountsAsAmmo |
If enabled, then every single bullet coming out will count toward ammo usage if limitedAmmo is enabled.
(Disable this for shotguns for example so that 10 bullets come out as spray, but only count as one 'bullet' used for ammo).
BulletOption WeaponSystem.bulletOptionType |
float WeaponSystem.bulletRandomness |
An amount of randomness to add to bullets when firing them (adds jitter to bullet streams / patterns).
float WeaponSystem.bulletSpacing |
The spacing between bullets when using more than one bullet.
float WeaponSystem.bulletSpeed |
Speed at which bullets travel
float WeaponSystem.bulletSpread |
The spread that bullets will use for their pattern (when more than one bullet)
float WeaponSystem.bulletSpreadPingPongMax |
The maximum spread to bounce up to when ping pong spread is enabled.
float WeaponSystem.bulletSpreadPingPongMin |
The minimum spread to bounce down to when ping pong spread is enabled.
bool WeaponSystem.circularFireMode |
When enabled, this will rotate the gun point transform around 360 degrees at a constant rate, allowing you to form circular bullet patterns.
Requires weapon system to be set to GunPoint relative mode.
float WeaponSystem.circularFireRotationRate = 240f |
The rotations per minute that the gunPoint transform will rotate with, if circularFireMode is enabled.
AudioClip WeaponSystem.emptySfxClip |
The empty magazine SFX clip for the selected weapon configuration
Transform WeaponSystem.gunPoint |
The gun point or transform location that bullets are shot / generated from when shooting.
This is used if the WeaponSystem configuration is set to relative to gun point mode.
bool WeaponSystem.hitEffectEnabled |
Enable if bullets from this weapon should spawn hit effects (like sparks for example) when impacting colliders.
bool WeaponSystem.isFirstEquip |
Used to track if a weapon configuration is the first equip or not.
bool WeaponSystem.lerpTurnRate |
If enabled, then the turn rate of a weapon system in 'Turret Track' mode whilst tracking its assigned target will be eased (instead of the weapon always instantly facing it's target).
bool WeaponSystem.limitedAmmo |
Enabled if the weapon configuration has limited ammo.
float WeaponSystem.magazineChangeDelay |
The time it takes to reload / change a magazine.
int WeaponSystem.magazineRemainingBullets |
Remaining bullets in the weapon configuration's magazine.
int WeaponSystem.magazineSize |
The number of bullets in a magazine.
bool WeaponSystem.mirrorX |
Duplicates the number of bullets being used and mirrors the extra bullets on the X-axis
bool WeaponSystem.pingPongSpread |
Enable to bounce the spread value of bullets between the pingpong spread min and max values (causes bullet pattern to 'swing' up and down).
bool WeaponSystem.playEmptySfx |
If enabled, then the empty SFX is played when attempting to shoot with an empty clip.
bool WeaponSystem.playReloadingSfx |
Allow the playback of the reloading SFX when reloading.
AudioClip WeaponSystem.reloadSfxClip |
The reload SFX clip for the selected weapon configuration
bool WeaponSystem.richochetsEnabled |
Enable if bullets fired from the weapon should allow ricochets (based on percent chance for bullets to ricochet).
float WeaponSystem.ricochetChancePercent |
The chance a bullet fired from this weapon will have to bounce / ricochet off other colliders.
ShooterType WeaponSystem.shooterDirectionType |
AudioClip WeaponSystem.shotFiredClip |
The shot fired SFX clip for the selected weapon configuration
float WeaponSystem.spreadPingPongSpeed = 1f |
The speed at which the bullet spread is bounced between.
int WeaponSystem.startingAmmo |
The starting ammo for a weapon configuration.
Transform WeaponSystem.targetToTrack |
The target for the weapon to track in 'Turret Track' mode.
float WeaponSystem.trackingTurnRate |
The rate at which a weapon in 'Turret Track' mode will turn to face it's designated target.
bool WeaponSystem.usesMagazines |
Enabled if the weapon is configured to have ammo and use magazines.
float WeaponSystem.weaponFireRate |
Texture2D WeaponSystem.weaponIcon |
The texture2D assigned to a weapon configuration - can be used for GUI display of selected weapon for example.
string WeaponSystem.weaponName |
The name assigned to the weapon configuration that is currently equipped.
bool WeaponSystem.weaponRelativeToComponent |
If enabled, the aiming/facing direction is calculated relative to the transform that the WeaponSystem component is placed on.
Offset X and Y positioning of bullets is taken into account and applied in this mode.
float WeaponSystem.weaponXOffset |
Offset on the X to position the start of a bullet when fired from a 'gunPoint' transform.
float WeaponSystem.weaponYOffset |
Offset on the Y to position the start of a bullet when fired from a 'gunPoint' transform.
|
getset |
(Legacy - pre version 1.3, but still usable) This property dictates what weapon is selected for the WeaponSystem.
Set it to any BulletPresetType Enum value and the event should take care of setting up the weapon for you. Just ensure that if you add a new Enum value to BulletPresetType, that you create an entry for it in the switch statement in the BulletPresetChangedHandler. All you need is a reference to your WeaponSystem script, once you have that, you can change you weapon selection from anywhere in your game using this.
|
getset |
The list of weapon configurations on this Weapon System.
BulletPresetChangeHandler WeaponSystem.BulletPresetChanged |
Event that fires when a bullet preset is changed.
ReloadFinishedHandler WeaponSystem.ReloadFinished |
Event that fires when reloading finishes.
ReloadStartedHandler WeaponSystem.ReloadStarted |
Event that fires when reloading starts.
WeaponConfigurationChangedHandler WeaponSystem.WeaponConfigurationChanged |
Event that fires when a Weapon Configuration is changed (weapon changed).
WeaponShootingFinishedHandler WeaponSystem.WeaponShootingFinished |
Event that fires when shooting stops.
WeaponShootingStartedHandler WeaponSystem.WeaponShootingStarted |
Event that fires when shooting starts.