Skip to content

Instantly share code, notes, and snippets.

@Shogan
Created August 18, 2015 08:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shogan/6fcfd61dfcb01a76800b to your computer and use it in GitHub Desktop.
Save Shogan/6fcfd61dfcb01a76800b to your computer and use it in GitHub Desktop.
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