Skip to content

Instantly share code, notes, and snippets.

@runevision
Created September 1, 2015 18:30
Show Gist options
  • Select an option

  • Save runevision/f1ddbb494de0baf9fb9c to your computer and use it in GitHub Desktop.

Select an option

Save runevision/f1ddbb494de0baf9fb9c to your computer and use it in GitHub Desktop.
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);
}
}
}
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);
}
}
}
@willhellwarth
Copy link
Copy Markdown

Thanks for sharing! Handy little class to save time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment