So, I am pretty new to this. But I know the overlap collects all colliders into an array however it also removes the items in that array after leaving. I am grabbing these objects and putting them in a list to check if its colliding with it, but the problem is when the objects leave, they don’t leave the list or update the bools to false. Is there a way for me to check if the specific object is no longer inside the overlap sphere or am I going to have to use overlap and Box Collider
//Grabs all collisions
size = new Vector3(halfX, halfY, halfZ);
center = new Vector3(transform.position.x, transform.position.y, transform.position.z);
collisions = Physics.OverlapBox(center, size/2, Quaternion.identity);
int i = 0;
while(i < collisions.Length)
{
//Debug.Log("Collided " + collisions[i].tag + i);
i++;
}
Transform[] childTransform = parent.GetComponentsInChildren<Transform>();
foreach(Transform child in childTransform)
{
if(!children.Contains(child))
{
//Keeps from adding the children colliders in the list
children.Add(child);
}
}
foreach(Collider col in collisions)
{
if(!children.Contains(col.transform))
{
if(!obj.Contains(col.gameObject))
{
//Adds the actual collisions to the list
obj.Add(col.gameObject);
}
}
}