Can i Check if a gameobject is colliding another object with a certain tag at every frame but without using OnTriggerStay?
Sometime the object that is tagged get inactive and then it doesnt change the bool value reffered to that collision.i dont want to destroy the gameobject instend of setting it inactive. OnTriggerExit doesnt even work in that case because it doesnt detect the gameobject exitting the other one…
Thanks!!
@jeffbori how about… (i deleted my answer because the code provided is much more efficient - @r3david 's suggestion)
public int collisionRadius;
public int checkRate;
public LayerMask targetMask;
Collider[] colliders; //colliders of objects are stored in this array
void Start()
{
StartCoroutine(CheckCollisions());
}
IEnumerator CheckCollisions()
{
while (isActiveAndEnabled)
{
colliders = Physics.OverlapSphere(transform.position, collisionRadius, targetMask);
yield return new WaitForSeconds(checkRate);
}
}