- Home /
Overlap Sphere not detecting prefabs of the same object
This is my first question here, so please forgive me if I make some mistakes.
I am making a simple RTS for practice programming and etc, and I've hit a snag. I looked around and couldn't find a satisfactory answer to my problem which is thus:
I have a tank prefab, which uses an OverlapSphere to detect objects within its attack range. If I place an additional tank prefab in the scene the two don't seem to detect each other with the OverlapSphere.
The code involving the OverlapSphere is here: _targetList = new List(); //hold all contacts in a temporary list
List<Collider> tempTargetList = Physics.OverlapSphere(transform.position, _atkRange).ToList<Collider>();
foreach (Collider collider in tempTargetList)
{
Debug.Log(collider.transform);
//assign any living contacts to the target list
if (collider.GetComponent<InteractableScript>() && collider.GetComponent<InteractableScript>().IsAlive)
{
_targetList.Add(collider);
}
}
Thanks in advance for any advice.
Never$$anonymous$$d this question, it's important to note that even a tank made up of compound colliders needs an initial collider or you end up with a problem like this. It was my mistake in the end, as usual.