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

Detailed Description

Put this script on objects you want to damage entities upon colliding with them. Useful for stage hazards, such as the Falling Spike.prefab.

Documentation updated 8/26/2024

Author
Stephen Nuttall
Note
There is a similar script called DamageOnTrigger that does the same thing for objects whose Collider2D has isTrigger checked off in the editor. This requires a different function to be used, which is why there's a separate script for it.
Todo
Replace damageNonPlayers and damagePlayer bools with one layer mask that allows for more choices in what is damaged.

Public Attributes

int colisionDamage = 40
 Amount of damage to apply when upon colliding with an object (that can be damaged).
 
bool damageNonPlayers = true
 If true, entities that are not the player will take damage when colliding with this object.
 
bool damagePlayer = true
 If true, the player will take damage when colliding with this object.
 
bool destroyOnCollision = true
 If true, the object will be destroyed as soon as it collides with something (regardless of if it's damagable or not).
 

Private Member Functions

void OnCollisionEnter2D (Collision2D col)
 When an object collides with this object, damage it if it has an object health (unless damageNonPlayers or damagePlayer dictates otherwise). Then destroy the game object (if destroyOnCollision is true).
 

Member Function Documentation

◆ OnCollisionEnter2D()

void DamageOnCollision.OnCollisionEnter2D ( Collision2D col)
private

When an object collides with this object, damage it if it has an object health (unless damageNonPlayers or damagePlayer dictates otherwise). Then destroy the game object (if destroyOnCollision is true).

Parameters
colRepresents the object that collided with this object.

Member Data Documentation

◆ colisionDamage

int DamageOnCollision.colisionDamage = 40

Amount of damage to apply when upon colliding with an object (that can be damaged).

◆ damageNonPlayers

bool DamageOnCollision.damageNonPlayers = true

If true, entities that are not the player will take damage when colliding with this object.

◆ damagePlayer

bool DamageOnCollision.damagePlayer = true

If true, the player will take damage when colliding with this object.

◆ destroyOnCollision

bool DamageOnCollision.destroyOnCollision = true

If true, the object will be destroyed as soon as it collides with something (regardless of if it's damagable or not).


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