Created
September 1, 2015 18:30
-
-
Save runevision/f1ddbb494de0baf9fb9c to your computer and use it in GitHub Desktop.
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
using UnityEngine; | |
using System.Collections; | |
using UnityEngine.Events; | |
namespace Cluster { | |
public class CollisionCall : MonoBehaviour { | |
public LayerMask layerMask = -1; | |
[System.Serializable] | |
public class CollisionEvent : UnityEvent<Collision> {} | |
public CollisionEvent onCollisionEnter; | |
public CollisionEvent onCollisionExit; | |
void OnCollisionEnter (Collision col) { | |
if ((layerMask.value & 1 << col.gameObject.layer) != 0) | |
onCollisionEnter.Invoke (col); | |
} | |
void OnCollisionExit (Collision col) { | |
if ((layerMask.value & 1 << col.gameObject.layer) != 0) | |
onCollisionExit.Invoke (col); | |
} | |
} | |
} |
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
using UnityEngine; | |
using System.Collections; | |
using UnityEngine.Events; | |
namespace Cluster { | |
public class TriggerCall : MonoBehaviour { | |
public LayerMask layerMask = -1; | |
[System.Serializable] | |
public class TriggerEvent : UnityEvent<Collider> {} | |
public TriggerEvent onTriggerEnter = new TriggerEvent (); | |
public TriggerEvent onTriggerExit = new TriggerEvent (); | |
void OnTriggerEnter (Collider col) { | |
if ((layerMask.value & 1 << col.gameObject.layer) != 0) | |
onTriggerEnter.Invoke (col); | |
} | |
void OnTriggerExit (Collider col) { | |
if ((layerMask.value & 1 << col.gameObject.layer) != 0) | |
onTriggerExit.Invoke (col); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for sharing! Handy little class to save time.