Eye of the Nile Docs
Everything you need to know to get started!
Loading...
Searching...
No Matches
BaseProjectile Class Reference

Detailed Description

Basic projectile functionality that every other projectile type must inherit from to be compatible with other systems (like the attack manager). You can also put this script onto any object or prefab to give it normal projectile functionality.

Documentation updated 11/13/2024

Author
Stephen Nuttall, Roy Pascual
Note
This script no longer handles projectile movement on its own. Instead, it supports any script that inherits from RudimentaryMovement, which must be attached separately. This is to make BaseProjectile a more universal solution to projectiles, since each projectile moves differently.
Todo
Replace damagePlayers and damageNonPlayers bools with one layer mask that allows for more choices in what is damaged.

Public Member Functions

void FlipDirection ()
 

Protected Member Functions

virtual void AwakeMethods ()
 Runs when Awake() is called.
 
virtual void StartMethods ()
 Plays the spawn sound effect.
 
virtual void OnTriggerEnterMethods (Collider2D collision)
 Runs if the projectile collides with an object (and it's a trigger zone). Does nothing by default.
 
virtual void OnCollisionEnterMethods (Collision2D collisionInfo)
 Runs if the projectile collides with an object. Damages the object it collided with if possible, then destroys the projectile.

Parameters
collisionInfoRepresents the object the projectile collided with.

 
void UpdateFacing ()
 Flips the sprite and movement direction (if a compatable component for projectile movement is attached) depending on if the projectile is currently facing left or right.
 

Protected Attributes

GameObject sprite
 Reference to the game object that holds the sprite renderer of the projectile. Often this is just the projectile itself, but sometimes there's a child with the sprite. This allows compatability with both systems.
 
int damage = 30
 The amount of damage the projectile will apply if it comes in contact with something it can damage.
 
bool damagePlayers = true
 If true, the projectile can damage the player.
 
bool damageNonPlayers = true
 If true, the projectile can damage objects that aren't the player (assuming they have an ObjectHealth component).
 
bool destroyOnImpact = true
 If true, the projectile will destroy itself when it hits something (regardless of if it can damage it or now).
 
EventReference spawnSFX
 Sound effect that plays when the projectile is spawned in.
 
bool flipSprite = true
 When facingLeft is true, the sprite will be flipped. Usually used to make the sprite "face the way the projectile is moving.".
 

Properties

int refDamage [get, private set]
 A mirror of damage that allows for other objects to read its value without changing it, and also allowing damage to appear in the Unity Editor.
 
bool facingLeft = false [get, private set]
 True if the projectile is facing (and thus moving) to the left. Likewise, false if the projectile is facing to the right.
 

Private Member Functions

void Awake ()
 Updates the direction the projectile is facing and runs AwakeMethods(), which can be changed in scripts that inherit from BaseProjectile.
 
void Start ()
 Runs StartMethods(), which can be changed in scripts that inherit from BaseProjectile.
 
void OnTriggerEnter2D (Collider2D collision)
 Runs OnTriggerEnterMethods(), which can be changed in scripts that inherit from BaseProjectile. This is required if your projectile's Collider2D component is set to be a trigger.
 
void OnCollisionEnter2D (Collision2D collisionInfo)
 Runs OnCollisionEnterMethods(), which can be changed in scripts that inherit from BaseProjectile. Afterwards, destroys the projectile, if enabled.
 

Member Function Documentation

◆ Awake()

void BaseProjectile.Awake ( )
private

Updates the direction the projectile is facing and runs AwakeMethods(), which can be changed in scripts that inherit from BaseProjectile.

◆ AwakeMethods()

virtual void BaseProjectile.AwakeMethods ( )
protectedvirtual

Runs when Awake() is called.

Currently does nothing and exists so inheriting functions can use it.

Reimplemented in BoneProjectile, and BoulderProjectile.

◆ FlipDirection()

void BaseProjectile.FlipDirection ( )

Flip the direction the projectile is facing (and thus moving). Switches facingLeft to be the opposite of what it currently is.

◆ OnCollisionEnter2D()

void BaseProjectile.OnCollisionEnter2D ( Collision2D collisionInfo)
private

Runs OnCollisionEnterMethods(), which can be changed in scripts that inherit from BaseProjectile. Afterwards, destroys the projectile, if enabled.

Parameters
collisionInfoRepresents the object the projectile collided with.

◆ OnCollisionEnterMethods()

virtual void BaseProjectile.OnCollisionEnterMethods ( Collision2D collisionInfo)
protectedvirtual

Runs if the projectile collides with an object. Damages the object it collided with if possible, then destroys the projectile.

Parameters
collisionInfoRepresents the object the projectile collided with.

Steps: If the object we collided with has an ObjectHealth AND at least one of the following is true:

  1. both damageNonPlayers AND damagePlayers are true
  2. the object is NOT the player AND damangeNonPlayers is true
  3. the object is the player AND damangePlayers is true, then apply damage to the object.

Reimplemented in BoneProjectile, BoulderProjectile, and EarthquakeProjectile.

◆ OnTriggerEnter2D()

void BaseProjectile.OnTriggerEnter2D ( Collider2D collision)
private

Runs OnTriggerEnterMethods(), which can be changed in scripts that inherit from BaseProjectile. This is required if your projectile's Collider2D component is set to be a trigger.

Parameters
collisionRepresents the object the projectile collided with.

◆ OnTriggerEnterMethods()

virtual void BaseProjectile.OnTriggerEnterMethods ( Collider2D collision)
protectedvirtual

Runs if the projectile collides with an object (and it's a trigger zone). Does nothing by default.

Note
This function only called if the projectile's Collider2D component is set to be a trigger. This is an option that makes the object have no collision, but sets off OnTriggerEnter2D() if anything steps into it (usually for something like a finish line in a race, or something similar). The basic projectile is not set to be a trigger, so this function isn't used in BaseProjectile. A script inheriting from it for a projectile that is a trigger though (maybe a laser that goes through multiple enemies) could use this.
Parameters
collisionRepresents the object the projectile collided with.

Reimplemented in BoneProjectile.

◆ Start()

void BaseProjectile.Start ( )
private

Runs StartMethods(), which can be changed in scripts that inherit from BaseProjectile.

◆ StartMethods()

virtual void BaseProjectile.StartMethods ( )
protectedvirtual

Plays the spawn sound effect.

Reimplemented in BoneProjectile, BoulderProjectile, and TornadoProjectile.

◆ UpdateFacing()

void BaseProjectile.UpdateFacing ( )
protected

Flips the sprite and movement direction (if a compatable component for projectile movement is attached) depending on if the projectile is currently facing left or right.

Member Data Documentation

◆ damage

int BaseProjectile.damage = 30
protected

The amount of damage the projectile will apply if it comes in contact with something it can damage.

◆ damageNonPlayers

bool BaseProjectile.damageNonPlayers = true
protected

If true, the projectile can damage objects that aren't the player (assuming they have an ObjectHealth component).

◆ damagePlayers

bool BaseProjectile.damagePlayers = true
protected

If true, the projectile can damage the player.

◆ destroyOnImpact

bool BaseProjectile.destroyOnImpact = true
protected

If true, the projectile will destroy itself when it hits something (regardless of if it can damage it or now).

◆ flipSprite

bool BaseProjectile.flipSprite = true
protected

When facingLeft is true, the sprite will be flipped. Usually used to make the sprite "face the way the projectile is moving.".

◆ spawnSFX

EventReference BaseProjectile.spawnSFX
protected

Sound effect that plays when the projectile is spawned in.

◆ sprite

GameObject BaseProjectile.sprite
protected

Reference to the game object that holds the sprite renderer of the projectile. Often this is just the projectile itself, but sometimes there's a child with the sprite. This allows compatability with both systems.

Property Documentation

◆ facingLeft

bool BaseProjectile.facingLeft = false
getprivate set

True if the projectile is facing (and thus moving) to the left. Likewise, false if the projectile is facing to the right.

◆ refDamage

int BaseProjectile.refDamage
getprivate set

A mirror of damage that allows for other objects to read its value without changing it, and also allowing damage to appear in the Unity Editor.


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