BaseWeapon.cs
Description
The base weapon class for all weapons used in the game, both by the enemies and by the player.
Script
Public Methods
- Fire()
Fires the weapon. Make sure the weapon is currently able to shoot. If used by player, then play the firing audio, and proceeds to decrement the primary ammo value. Starts the weapon firing cooldown.
- Reload()
Reload the weapon. Check if ammo is already full or if already reloading. Plays the reload sound, and calculates the new value. Start the reload cooldown, and if the player uses the weapon, update the UI elements to visualise the reload time.
Private Methods
- ReloadCooldown()
Receives an integer input of the updated primary ammo value. Waits for the specified reload duration, then calculates the new secondary and primary ammo, and then returns the weapon back to the idle state.
- WeaponCooldown()
Updates the weapon state to show it is currently shooting. Calculates the weapon cooldown based upon the fire-rate. Waits for that amount of time, and then returns the weapon to the idle state.
Protected Methods
- GetWeaponSpread()
Calculates the weapon spread. Randomises the Vectors X, Y and Z axis by using both negative and positive values of the spread value. Returns the new direction.
Components
- tutorialController
The tutorial scene manager component.
- playerController
The player controller component.
Public Variables
- bulletCasingSpawnPos
The location on the weapon for the weapon casing to be ejected from.
- layersToHitScan
The layers that the raycast can hit, and the layers that can be ignored.
- maxPrimaryAmmo
The maximum value that can be stored in one magazine before reloading.
- maxSecondaryAmmo
The maximum value of ammo that can be carried for reloading.
- pistolBulletCasing
The bullet casing to be spawned upon firing a pistol.
- reloadSound
The sound to be played when the weapon is reloaded.
- shootingType
Determines whether the weapon will be using projectiles, or use raycasts (hitscan).
- shotgunBulletCasing
The bullet casing to be spawned upon firing a shotgun.
- shotgunPelletCount
The amount of pellet projectiles to be shot by the shotgun weapon.
- spawnPosition
The spawn position for the projectiles or raycasts to originate from.
- weaponAction
Used to store the current state of the weapon. Uses an enum structure, so can only be pre-determined states.
- weaponDamage
The damage the weapon will do.
- weaponFireRate
How fast the weapon can be fired.
- weaponProjectile
The projectile GameObject used by the weapon.
- weaponRange
The max range the weapon can reach.
- weaponReloadTime
The time to take when reloading.
- weaponSound
The sound to be played when the weapon is fired.
- weaponSpread
The max radius of spread / scatter the weapon has.
Private Variables
- projectileSpeed
How fast the projectile objects will travel at.
- projectileSpawnTime
The amount of lifetime the projectile can have in-game.
Encapsulated Variables
- CurrentPrimaryAmmo
Public reference to the weapons current primary ammo.
- CurrentSecondaryAmmo
Public reference to the weapons current secondary ammo.
- ProjectileSpeed
Public reference to the weapons projectile speed.
- ProjectileDespawnTime
Public reference to the weapons despawn time.