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

Detailed Description

If something enters this object's trigger zone, this script will spawn an object or projectile. This is useful for stage hazards, such as the arrow trap.

Documentation updated 1/31/2025

Author
Stephen Nuttall, Alexander Art

Public Attributes

GameObject projectilePrefab
 Projectile to spawn when an object enters the trigger zone.
 
Transform spawnPoint
 Position where the projectile should be spawned.
 
float spawnCooldown = 3f
 How long, in seconds, until another projectile can be spawned.
 
bool facingLeft = true
 Should the projectile be facing left?
 
bool playerOnly = true
 Should enemies be able to activate the trigger zone, or just the player?
 

Private Member Functions

void Start ()
 Start cooldownTimer at spawnCooldown so the projectile can be spawned immediately.
 
void Update ()
 Increase cooldownTimer by the amount of time that's passed since the last frame.
 
void OnTriggerEnter2D (Collider2D col)
 If an object enters the trigger zone (and the cooldown is up), instantiate a new instance of projectilePrefab. If playerOnly is enabled, only the player can trigger the projectile. Make sure it's facing the right direction (if projectilePrefab is actually a BasicProjectile), and reset the cooldown timer.
 

Private Attributes

float cooldownTimer = 0f
 Seconds since cooldown was last started. When greater than spawnCooldown, cooldown is over.
 

Member Function Documentation

◆ OnTriggerEnter2D()

void SpawnOnTrigger.OnTriggerEnter2D ( Collider2D col)
private

If an object enters the trigger zone (and the cooldown is up), instantiate a new instance of projectilePrefab. If playerOnly is enabled, only the player can trigger the projectile. Make sure it's facing the right direction (if projectilePrefab is actually a BasicProjectile), and reset the cooldown timer.

Parameters
colRepresents the object that's entered the trigger zone.

◆ Start()

void SpawnOnTrigger.Start ( )
private

Start cooldownTimer at spawnCooldown so the projectile can be spawned immediately.

◆ Update()

void SpawnOnTrigger.Update ( )
private

Increase cooldownTimer by the amount of time that's passed since the last frame.

Member Data Documentation

◆ cooldownTimer

float SpawnOnTrigger.cooldownTimer = 0f
private

Seconds since cooldown was last started. When greater than spawnCooldown, cooldown is over.

◆ facingLeft

bool SpawnOnTrigger.facingLeft = true

Should the projectile be facing left?

◆ playerOnly

bool SpawnOnTrigger.playerOnly = true

Should enemies be able to activate the trigger zone, or just the player?

◆ projectilePrefab

GameObject SpawnOnTrigger.projectilePrefab

Projectile to spawn when an object enters the trigger zone.

◆ spawnCooldown

float SpawnOnTrigger.spawnCooldown = 3f

How long, in seconds, until another projectile can be spawned.

◆ spawnPoint

Transform SpawnOnTrigger.spawnPoint

Position where the projectile should be spawned.


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