Third Person Cover Shooter  1.6
CoverShooter.BaseGun Class Referenceabstract

Guns raycasts bullets, manage magazine and recoil. More...

Inheritance diagram for CoverShooter.BaseGun:
CoverShooter.Gun

Public Member Functions

void ToUse ()
 Command to use the weapon. More...
 
virtual void OnMagazineLoadStart ()
 Notified of a magazine load start by the CharacterMotor. More...
 
virtual void OnBulletLoadStart ()
 Notified of a magazine load start by the CharacterMotor. More...
 
virtual void OnPumpStart ()
 Notified of a magazine load start by the CharacterMotor. More...
 
virtual void OnPumped ()
 Notified of a magazine load start by the CharacterMotor. More...
 
void NotifyRechamber ()
 
void NotifyEject ()
 
void NotifyPumpStart ()
 
void NotifyPump ()
 
void NotifyMagazineLoadStart ()
 
void NotifyBulletLoadStart ()
 
void IgnoreSelf (bool value=true)
 Sets the gun to ignore hitting it's owner. More...
 
void SetFireCondition (int side)
 Sets the gun to not fire if aiming at a friend. More...
 
void CancelFireCondition ()
 Sets the gun to fire in any condition. More...
 
GameObject FindCurrentAimedTarget ()
 Returns a game object the gun is currently aiming at. More...
 
GameObject FindCurrentAimedHealthTarget ()
 Returns a game object with CharacterHealth the gun is currently aiming at. More...
 
abstract bool LoadMagazine ()
 Reload whole magazine. More...
 
abstract bool LoadBullet ()
 Add a single bullet to the magazine. More...
 
RaycastHit Raycast ()
 Finds an object and a hit position a bullet would hit if fired. More...
 
RaycastHit Raycast (Vector3 origin, Vector3 direction, out bool isFriend, bool friendCheck)
 Finds an object and a hit position a bullet would hit if fired. More...
 
void TryFireNow ()
 Sets the gun to try firing during the next update. More...
 
void FireWhenReady ()
 Sets the fire mode on. More...
 
void CancelFire ()
 Sets the fire mode off. More...
 
void Allow (bool value)
 Sets whether the gun is allowed to fire. More...
 
void SetupRaycastThisFrame (Vector3 origin, Vector3 target)
 Sets the position from which bullets are spawned. More...
 
void AddErrorThisFrame (float degrees)
 Sets the aim error in degrees for the next frame. More...
 
void SetBaseErrorMultiplierThisFrame (float multiplier)
 Sets the base error (Error property) multiplier for this frame. More...
 
void UpdateManually ()
 Call the update method manually. More...
 

Public Attributes

WeaponType Type = WeaponType.Pistol
 Animations and related assets to be used with this weapon. More...
 
string Name = "Gun"
 Name of the gun to be display on the HUD. More...
 
float Zoom = 30
 How many degrees should the camera FOV be reduced when using scope on the gun. More...
 
Sprite Scope
 Sprite that's displayed when zooming in. More...
 
float Rate = 7
 Rate of fire in shots per second. More...
 
int BulletsPerShot = 1
 Bullets fired per single shot. More...
 
bool ConsumeSingleBulletPerShot = true
 If firing multiple bullets per shot, should only a single bullet be removed from the inventory. More...
 
float Distance = 50
 Maximum distance of a bullet hit. More...
 
float Damage = 10
 Damage dealt by a single bullet. More...
 
float Error = 0
 Maximum degrees of error the gun can make when firing. More...
 
bool AutoReload = false
 Should the gun be reloaded automatically when the magazine is empty. More...
 
bool ReloadWithMagazines = true
 Is the gun reloaded with whole magazines or bullet by bullet. More...
 
bool CanInterruptBulletLoad = true
 If reloading bullet by bullet, can the gun be fired during reload. More...
 
bool PumpAfterFinalLoad = false
 After a new magazine or the last bullet is loaded, should the gun be pumped. More...
 
bool PumpAfterBulletLoad = false
 Should the gun be pumped after each bullet load. More...
 
bool PumpAfterFire = false
 Should the gun be pumped after firing a shot. More...
 
bool FireOnMobileAim = true
 Will the character fire by just aiming the mobile controller. More...
 
bool LaserOnlyOnZoom = true
 Should the laser be visible only when zooming. More...
 
bool DebugAim = false
 Should a debug ray be displayed. More...
 
GameObject Aim
 Link to the object that controls the aiming direction. More...
 
GameObject Bullet
 Object to be instantiated as a bullet. More...
 
Transform LeftHandDefault
 Link to the object that controls the position of character's left hand relative to the weapon. More...
 
float DamageResponseWaitTime = 1
 Time in seconds between hits that the target character will respond to with hurt animations. More...
 
bool UseCustomCrosshair
 Should the gun's crosshair be used instead of the one set in the Crosshair component. More...
 
CrosshairSettings CustomCrosshair = CrosshairSettings.Default()
 Custom crosshair settings to override the ones set in the Crosshair component. More...
 
GunRecoilSettings Recoil = GunRecoilSettings.Default()
 Settings that manage gun's recoil behaviour. More...
 
HandOverwrite LeftHandOverwrite
 Links to objects that overwrite the value in LeftHand based on the gameplay situation. More...
 
Laser LaserOverwrite
 Force the pistol to use this laser instead of finding one on its own. More...
 
CharacterMotor Character
 Owning object with a CharacterMotor component. More...
 
Action MagazineLoadStarted
 Event executed at the beginning of a magazine load animation. More...
 
Action FullyLoaded
 Event executed after the gun has been fully loaded. More...
 
Action BulletLoadStarted
 Event executed at the beginning of a bullet load animation. More...
 
Action BulletLoaded
 Event executed after a bullet has been loaded. More...
 
Action PumpStarted
 Event executed at the start of a pump animation. More...
 
Action Pumped
 Event executed at the end of a pump animation. More...
 
Action Fired
 Event executed after a successful fire. More...
 
Action EmptyFire
 Event executed every time there is an attempt to fire with no bullets in the gun. More...
 
Action FireStarted
 Event executed after a series of bullet fires as started. More...
 
Action FireStopped
 Event executed after a series of bullet fires has stopped. More...
 
Action< HitSuccessfulyHit
 Event executed after a bullet hit something. More...
 

Protected Member Functions

virtual void Start ()
 Get the LineRenderer if there is one. More...
 
virtual void Awake ()
 Finds the renderer. More...
 
virtual void Frame ()
 
abstract void Consume ()
 Consume a single bullet. More...
 

Properties

Vector3 Origin [get]
 Point of creation for bullets in world space. More...
 
Vector3 Direction [get]
 Direction of bullets when created at the origin. More...
 
bool CanHit [get]
 Whether the gun can be used to perform a melee hit right now. More...
 
bool HasJustFired [get]
 Returns true if the gun fired during the last update. More...
 
bool IsAllowed [get]
 Returns true if the gun is allowed to fire. More...
 
Renderer Renderer [get]
 Renderer attached to the object. More...
 
Vector3 RaycastOrigin [get]
 Origin to cast bullets from. More...
 
Vector3 RaycastTarget [get]
 Target position at which bullets are fired at. More...
 
bool HasRaycastSetup [get]
 Are raycast settings setup manually by some other component. More...
 
abstract bool CanLoad [get]
 Can the gun be loaded with more bullets. More...
 
abstract int LoadedBulletsLeft [get]
 Number of bullets left in the gun. More...
 
abstract bool IsFullyLoaded [get]
 Is the gun fully loaded with bullets. More...
 
abstract float LoadPercentage [get]
 Load percentage for the ammo ui. More...
 
IGunListener [] Listeners [get]
 

Detailed Description

Guns raycasts bullets, manage magazine and recoil.

For player characters bullets originate at camera in order for player to be able to fire on targets they can see, even if there is a small obstacle in front of the gun. The fire origin is set by a camera. Since AI do not have Third Person Camera attached their bullets are fired starting from the Aim marker, which usually is at the end of the gun. Each weapon has two marker objects. Aim defines point of origin for AI bullets and is also used when rotating character’s arms till the marker points towards the target. Left Hand object marks the position for character’s left hand. Naming of left and right hands refers to the general case as character’s handedness can be swapped. The intended position of the left hand might differ in some animations, to handle that there are left hand marker overwrites you can use to set up IK for the left hand for some specific situations. Empty values are not used as overwrites. Currently there are two kinds of weapons, pistols and rifles. The type defines character animations when using the weapon.

Member Function Documentation

◆ AddErrorThisFrame()

void CoverShooter.BaseGun.AddErrorThisFrame ( float  degrees)

Sets the aim error in degrees for the next frame.

Errors are stacked.

◆ Allow()

void CoverShooter.BaseGun.Allow ( bool  value)

Sets whether the gun is allowed to fire.

Manipulated when changing weapons or a reload animation is playing.

Parameters
value

◆ Awake()

virtual void CoverShooter.BaseGun.Awake ( )
protectedvirtual

Finds the renderer.

◆ CancelFire()

void CoverShooter.BaseGun.CancelFire ( )

Sets the fire mode off.

◆ CancelFireCondition()

void CoverShooter.BaseGun.CancelFireCondition ( )

Sets the gun to fire in any condition.

◆ Consume()

abstract void CoverShooter.BaseGun.Consume ( )
protectedpure virtual

Consume a single bullet.

Implemented in CoverShooter.Gun.

◆ FindCurrentAimedHealthTarget()

GameObject CoverShooter.BaseGun.FindCurrentAimedHealthTarget ( )

Returns a game object with CharacterHealth the gun is currently aiming at.

◆ FindCurrentAimedTarget()

GameObject CoverShooter.BaseGun.FindCurrentAimedTarget ( )

Returns a game object the gun is currently aiming at.

◆ FireWhenReady()

void CoverShooter.BaseGun.FireWhenReady ( )

Sets the fire mode on.

It stays on until CancelFire() is called or the gun has fired. Gun fires only when both fire mode is on and the gun is allowed to fire.

◆ Frame()

virtual void CoverShooter.BaseGun.Frame ( )
protectedvirtual

◆ IgnoreSelf()

void CoverShooter.BaseGun.IgnoreSelf ( bool  value = true)

Sets the gun to ignore hitting it's owner.

◆ LoadBullet()

abstract bool CoverShooter.BaseGun.LoadBullet ( )
pure virtual

Add a single bullet to the magazine.

Implemented in CoverShooter.Gun.

◆ LoadMagazine()

abstract bool CoverShooter.BaseGun.LoadMagazine ( )
pure virtual

Reload whole magazine.

Implemented in CoverShooter.Gun.

◆ NotifyBulletLoadStart()

void CoverShooter.BaseGun.NotifyBulletLoadStart ( )

◆ NotifyEject()

void CoverShooter.BaseGun.NotifyEject ( )

◆ NotifyMagazineLoadStart()

void CoverShooter.BaseGun.NotifyMagazineLoadStart ( )

◆ NotifyPump()

void CoverShooter.BaseGun.NotifyPump ( )

◆ NotifyPumpStart()

void CoverShooter.BaseGun.NotifyPumpStart ( )

◆ NotifyRechamber()

void CoverShooter.BaseGun.NotifyRechamber ( )

◆ OnBulletLoadStart()

virtual void CoverShooter.BaseGun.OnBulletLoadStart ( )
virtual

Notified of a magazine load start by the CharacterMotor.

◆ OnMagazineLoadStart()

virtual void CoverShooter.BaseGun.OnMagazineLoadStart ( )
virtual

Notified of a magazine load start by the CharacterMotor.

◆ OnPumped()

virtual void CoverShooter.BaseGun.OnPumped ( )
virtual

Notified of a magazine load start by the CharacterMotor.

◆ OnPumpStart()

virtual void CoverShooter.BaseGun.OnPumpStart ( )
virtual

Notified of a magazine load start by the CharacterMotor.

◆ Raycast() [1/2]

RaycastHit CoverShooter.BaseGun.Raycast ( )

Finds an object and a hit position a bullet would hit if fired.

◆ Raycast() [2/2]

RaycastHit CoverShooter.BaseGun.Raycast ( Vector3  origin,
Vector3  direction,
out bool  isFriend,
bool  friendCheck 
)

Finds an object and a hit position a bullet would hit if fired.

Checks if it is a friend.

◆ SetBaseErrorMultiplierThisFrame()

void CoverShooter.BaseGun.SetBaseErrorMultiplierThisFrame ( float  multiplier)

Sets the base error (Error property) multiplier for this frame.

◆ SetFireCondition()

void CoverShooter.BaseGun.SetFireCondition ( int  side)

Sets the gun to not fire if aiming at a friend.

◆ SetupRaycastThisFrame()

void CoverShooter.BaseGun.SetupRaycastThisFrame ( Vector3  origin,
Vector3  target 
)

Sets the position from which bullets are spawned.

The game usually sets it as the camera position.

◆ Start()

virtual void CoverShooter.BaseGun.Start ( )
protectedvirtual

Get the LineRenderer if there is one.

◆ ToUse()

void CoverShooter.BaseGun.ToUse ( )

Command to use the weapon.

◆ TryFireNow()

void CoverShooter.BaseGun.TryFireNow ( )

Sets the gun to try firing during the next update.

Gun fires only when both fire mode is on and the gun is allowed to fire.

◆ UpdateManually()

void CoverShooter.BaseGun.UpdateManually ( )

Call the update method manually.

Performed by the CharacterMotor, in order to fire the weapon after the weapon has performed it's IK.

Member Data Documentation

◆ Aim

GameObject CoverShooter.BaseGun.Aim

Link to the object that controls the aiming direction.

◆ AutoReload

bool CoverShooter.BaseGun.AutoReload = false

Should the gun be reloaded automatically when the magazine is empty.

◆ Bullet

GameObject CoverShooter.BaseGun.Bullet

Object to be instantiated as a bullet.

◆ BulletLoaded

Action CoverShooter.BaseGun.BulletLoaded

Event executed after a bullet has been loaded.

◆ BulletLoadStarted

Action CoverShooter.BaseGun.BulletLoadStarted

Event executed at the beginning of a bullet load animation.

◆ BulletsPerShot

int CoverShooter.BaseGun.BulletsPerShot = 1

Bullets fired per single shot.

◆ CanInterruptBulletLoad

bool CoverShooter.BaseGun.CanInterruptBulletLoad = true

If reloading bullet by bullet, can the gun be fired during reload.

◆ Character

CharacterMotor CoverShooter.BaseGun.Character

Owning object with a CharacterMotor component.

◆ ConsumeSingleBulletPerShot

bool CoverShooter.BaseGun.ConsumeSingleBulletPerShot = true

If firing multiple bullets per shot, should only a single bullet be removed from the inventory.

◆ CustomCrosshair

CrosshairSettings CoverShooter.BaseGun.CustomCrosshair = CrosshairSettings.Default()

Custom crosshair settings to override the ones set in the Crosshair component.

Used only if UseCustomCrosshair is enabled.

◆ Damage

float CoverShooter.BaseGun.Damage = 10

Damage dealt by a single bullet.

◆ DamageResponseWaitTime

float CoverShooter.BaseGun.DamageResponseWaitTime = 1

Time in seconds between hits that the target character will respond to with hurt animations.

◆ DebugAim

bool CoverShooter.BaseGun.DebugAim = false

Should a debug ray be displayed.

◆ Distance

float CoverShooter.BaseGun.Distance = 50

Maximum distance of a bullet hit.

Objects further than this value are ignored.

◆ EmptyFire

Action CoverShooter.BaseGun.EmptyFire

Event executed every time there is an attempt to fire with no bullets in the gun.

◆ Error

float CoverShooter.BaseGun.Error = 0

Maximum degrees of error the gun can make when firing.

◆ Fired

Action CoverShooter.BaseGun.Fired

Event executed after a successful fire.

◆ FireOnMobileAim

bool CoverShooter.BaseGun.FireOnMobileAim = true

Will the character fire by just aiming the mobile controller.

◆ FireStarted

Action CoverShooter.BaseGun.FireStarted

Event executed after a series of bullet fires as started.

◆ FireStopped

Action CoverShooter.BaseGun.FireStopped

Event executed after a series of bullet fires has stopped.

◆ FullyLoaded

Action CoverShooter.BaseGun.FullyLoaded

Event executed after the gun has been fully loaded.

◆ LaserOnlyOnZoom

bool CoverShooter.BaseGun.LaserOnlyOnZoom = true

Should the laser be visible only when zooming.

◆ LaserOverwrite

Laser CoverShooter.BaseGun.LaserOverwrite

Force the pistol to use this laser instead of finding one on its own.

◆ LeftHandDefault

Transform CoverShooter.BaseGun.LeftHandDefault

Link to the object that controls the position of character's left hand relative to the weapon.

◆ LeftHandOverwrite

HandOverwrite CoverShooter.BaseGun.LeftHandOverwrite

Links to objects that overwrite the value in LeftHand based on the gameplay situation.

◆ MagazineLoadStarted

Action CoverShooter.BaseGun.MagazineLoadStarted

Event executed at the beginning of a magazine load animation.

◆ Name

string CoverShooter.BaseGun.Name = "Gun"

Name of the gun to be display on the HUD.

◆ PumpAfterBulletLoad

bool CoverShooter.BaseGun.PumpAfterBulletLoad = false

Should the gun be pumped after each bullet load.

◆ PumpAfterFinalLoad

bool CoverShooter.BaseGun.PumpAfterFinalLoad = false

After a new magazine or the last bullet is loaded, should the gun be pumped.

◆ PumpAfterFire

bool CoverShooter.BaseGun.PumpAfterFire = false

Should the gun be pumped after firing a shot.

◆ Pumped

Action CoverShooter.BaseGun.Pumped

Event executed at the end of a pump animation.

◆ PumpStarted

Action CoverShooter.BaseGun.PumpStarted

Event executed at the start of a pump animation.

◆ Rate

float CoverShooter.BaseGun.Rate = 7

Rate of fire in shots per second.

◆ Recoil

GunRecoilSettings CoverShooter.BaseGun.Recoil = GunRecoilSettings.Default()

Settings that manage gun's recoil behaviour.

◆ ReloadWithMagazines

bool CoverShooter.BaseGun.ReloadWithMagazines = true

Is the gun reloaded with whole magazines or bullet by bullet.

◆ Scope

Sprite CoverShooter.BaseGun.Scope

Sprite that's displayed when zooming in.

◆ SuccessfulyHit

Action<Hit> CoverShooter.BaseGun.SuccessfulyHit

Event executed after a bullet hit something.

◆ Type

WeaponType CoverShooter.BaseGun.Type = WeaponType.Pistol

Animations and related assets to be used with this weapon.

◆ UseCustomCrosshair

bool CoverShooter.BaseGun.UseCustomCrosshair

Should the gun's crosshair be used instead of the one set in the Crosshair component.

◆ Zoom

float CoverShooter.BaseGun.Zoom = 30

How many degrees should the camera FOV be reduced when using scope on the gun.

Property Documentation

◆ CanHit

bool CoverShooter.BaseGun.CanHit
get

Whether the gun can be used to perform a melee hit right now.

◆ CanLoad

abstract bool CoverShooter.BaseGun.CanLoad
get

Can the gun be loaded with more bullets.

◆ Direction

Vector3 CoverShooter.BaseGun.Direction
get

Direction of bullets when created at the origin.

◆ HasJustFired

bool CoverShooter.BaseGun.HasJustFired
get

Returns true if the gun fired during the last update.

◆ HasRaycastSetup

bool CoverShooter.BaseGun.HasRaycastSetup
get

Are raycast settings setup manually by some other component.

◆ IsAllowed

bool CoverShooter.BaseGun.IsAllowed
get

Returns true if the gun is allowed to fire.

◆ IsFullyLoaded

abstract bool CoverShooter.BaseGun.IsFullyLoaded
get

Is the gun fully loaded with bullets.

◆ Listeners

IGunListener [] CoverShooter.BaseGun.Listeners
getprotected

◆ LoadedBulletsLeft

abstract int CoverShooter.BaseGun.LoadedBulletsLeft
get

Number of bullets left in the gun.

◆ LoadPercentage

abstract float CoverShooter.BaseGun.LoadPercentage
get

Load percentage for the ammo ui.

◆ Origin

Vector3 CoverShooter.BaseGun.Origin
get

Point of creation for bullets in world space.

◆ RaycastOrigin

Vector3 CoverShooter.BaseGun.RaycastOrigin
get

Origin to cast bullets from.

◆ RaycastTarget

Vector3 CoverShooter.BaseGun.RaycastTarget
get

Target position at which bullets are fired at.

◆ Renderer

Renderer CoverShooter.BaseGun.Renderer
get

Renderer attached to the object.


The documentation for this class was generated from the following file: