Null Collision Detection

Hello!Sorry for the newbish question but how can i create a boolean variable that returns true if the object is colliding and false when it is not colliding with anything?I searched for it all the morning but found nothing.

var bool : boolean = true;

function OnCollisionStay(){
bool = true;
}

function OnCollisionExit(){
bool = false;
}

^ That didn't worked because as my object exits the collision on another object it will return true all of the time. :[ Please help me

Have you tried OnCollisionEnter instead of OnCollisionStay?

Try this:

var colliding:int = 0;

function OnCollisionEnter(collision : Collision):void{
      colliding++;
}

function OnCollisionExit(collision : Collision):void{
      colliding--;
}

Note that collision events are only sent if one of the colliders also has a non-kinematic rigid body attached.

EDIT:

You can also try using Physics.OverlapSphere or Physics.CheckCapsule instead.