Overlapsphere issue with laymask
Hello,
So I'm using an overlapshere to get an array of enemies in a radius, however, im using a layer mask to only find the enemy objects and I have no idea why it's not working!
My enemies are tagged with "NPC" and my unity physics settings allow the tower layer to collide with the NPC layer.
Code:
private void Awake()
{
targetLayer = LayerMask.NameToLayer("NPC");
}
private void Start()
{
InvokeRepeating("CheckForTargets", 0f, fireRate);
}
private void CheckForTargets()
{
print("CheckForTargets() Called!");
hitColliders = Physics.OverlapSphere(transform.position, attackRange, targetLayer);
if (hitColliders.Length > 0)
{
print("hitColliders.Length > 0");
target = hitColliders[hitColliders.Length - 1].gameObject;
}
}
The print("CheckForTargets() Called!"); is working, but it's not finding any objects.
Am I doing something wrong?
Thanks in advance!
Your answer
Follow this Question
Related Questions
Faster way to check if object has component? 1 Answer
Raycast hitting layer explicitly told to ignore (and doesn't even have collider!) 1 Answer
How to assign a layermask variable using code? 1 Answer
How to Ignore Collisions Between a Layer and a LayerMask? 1 Answer
collider Ignore player Raycast but not player rigid body or enemy raycasts 0 Answers