This is a great use case for Colliders in Unity. http://docs.unity3d.com/ScriptReference/Collider.html
You would actually want to achieve your objective using 2 colliders. The first being your Border Collider, the second being the "Play Space" collider.
You would then want a script for your GameObjects (squares/rectangles) which checks their collisions, and using a few variables determine which state you are describing.
An example (psuedo code) would be something like this:
using UnityEngine;
using System.Collections;
public class falling_game_block : MonoBehaviour {
bool border_collide = false;
bool playspace_collide = false;
void OnCollisionEnter(Collision collision_info)
{
if(collision_info.collider.name == "border_collider_name")
{
border_collide = true;
}//END IF COLLISION.COLLIDER == "BORDER_COLLIDER_HERE"
if(collision_info.collider.name == "playspace_collider_name")
{
playspace_collide = true;
}//END IF COLLISION.COLLIDER == "PLAYSPACE_COLLIDER_HERE"
print(gameObject.name + " in contact with " + collisionInfo.collider.name);
}//END FUNCTION ONCOLLISIONENTER
void OnCollisionExit(Collision collisionInfo) {
print(gameObject.name + " No longer in contact with " + collisionInfo.collider.name);
}
void Update()
{
if(border_collide == true && playspace_collide == true)
{
//DO stuff, explode, warn, cry, etc...
}//END IF BORDER_COLLIDE == TRUE AND PLAYSPACE_COLLIDE == TRUE
}
}//END CLASS FALLING_GAME_BLOCK
You'll want to look at the "console" to see the print messages. Comment them out when you understand what is going on.
*** Note this is just psuedo code, and is not fully tested... you may have to perform slight tweaks to address errors, and a few more tweaks to get it to handle your exact need, but this should provide a good starting point!!!
Collider
s are in Unity? \$\endgroup\$