Unity3D components and delegates for detecting whether a Collider2D is fully contained within another Collider2D.
Download the contained.unitypackage and import it into Unity
by going to Assets > Import Package > Custom Package. Choose contained.unitypackage
and import all assets.
Contained notifies components of horizontal containment only. In order to listen to these events, attach a
HorizontallyContained
component to your GameObject as well as the component that will be listening to these events. You can then subscribe to these events
by implementing the IHorizontallyContainedDelegate from within the Contained namespace. An example of this can be seen below:
using UnityEngine;
using Contained;
namespace Example {
public class ContainedListener : MonoBehaviour, IHorizontallyContained2DDelegate {
public void OnHorizontalContain(Collider2D other) {
Debug.Log("Listener notified of containment!");
}
public void OnHorizontalExit(Collider2D other) {
Debug.Log("Listener notified of exit!");
}
}
}