Created
August 18, 2015 08:57
-
-
Save Shogan/6fcfd61dfcb01a76800b to your computer and use it in GitHub Desktop.
Example of laser damage event with interval
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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