Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Example of laser damage event with interval
public delegate void LaserHitTriggerHandler(RaycastHit2D hitInfo);
/// <summary>
/// Event that fires whenever the laser collides with an object (requires ignoreCollisions to be false). Subscribe to this event to be notified when the laser is hitting an object. The RaycastHit2D info will be sent through the event.
/// </summary>
public event LaserHitTriggerHandler OnLaserHitTriggered;
/// <summary>
/// Fires the OnLaserHitTriggered event every triggerInterval seconds.
/// </summary>
/// <param name="triggerInterval"></param>
/// <param name="hit"></param>
/// <returns></returns>
private IEnumerator HitTrigger(float triggerInterval, RaycastHit2D hit)
waitingForTriggerTime = true;
if (OnLaserHitTriggered != null) OnLaserHitTriggered(hit);
yield return new WaitForSeconds(triggerInterval);
waitingForTriggerTime = false;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.