- Home /
Have "OnTriggerStay" detection but only call it once?
I'm at a point where trigger/enter/exits can't be used anymore. I need to detect if two objects are currently colliding via their triggers when the mouse clicks on them, since the triggers sometimes never enter or exit means nothing is refreshed... and TriggerStays are way to CPU intensive.
Is there some way to have a function which makes ONE CHECK to see if they are colliding? If only there was a "OnTriggerCheck" eh?
Any answers? I can't think of anything nearly as optimized as I need it. Virtual high 5 for the best answer :)
Answer by MibZ · Sep 20, 2012 at 11:32 PM
I'm currently working on a project that uses a lot of OnTrigger functions, a possible solution is to have a bool that changes in Enter and Exit.
//Inside variable declaration
bool intersecting;
Collider colliderToCheck;
void OnTriggerEnter(Collider other)
{
if (other == colliderToCheck)
intersecting = true;
}
void OnTriggerExit(Collider other)
{
if (other == colliderToCheck)
intersecting = false;
}
Alternatively, you can use Bounds.Intersects()
if (Bounds.Intersects(BoundingBox)
{
//TODO: Program stuff
}