Check if gameobject is in a box collider (C#)

Picture explanation: http://postimg.org/image/iks3gsuvr/ I have a game, and when a circle (gameObject) touches with the inner box collider gameObject, it gets destoryed. This works fine, however I have some game zones in which that box collider is there from a map generation, and I have a “protection” box collider around it. By Default if this circle GameObject touches the innerbox collider attached to a gameObject it dies. If the circle touches the innerbox, BUT does touch the outer box, nothing happens. Any Help?

You need to check if it contains your circle in OnTriggerStay2D function. You can achieve this by Boxcollider2D.bounds.contains() function.

Each of those colliders will produce a callback (OnTriggerXXX assuming they’re both triggers) so whether they’re on the same GameObject or on different ones, you’ll get two callbacks.

If these colliders are very specific to the game, you could simply use Collider2D.IsTouching to check if the circle (CircleCollider2D ?) is touching the outer & inner colliders. A simply script that refers to both the outer & innert could do this in a single line such as:

public CircleCollider2D circle;
public BoxCollider2D outer;
public BoxCollider2D inner;

void FixedUpdate ()
{
    if (circle.IsTouching (outer) && circle.IsTouching (inner))
        DoSomething ();
}