Physics.OverlapSphere is not detecting any 2D Box Colliders even though there are!
Hi, just to start off I'm pretty new to unity still and have started experimenting with a bunch of new things. Currently I am working on a game where the player can click a button and is able to see in an area around them any invisible platforms. I decided to go simple and made a code that basically when clicking the B button the Physics.OverlapSphere checks from the player position as center and then traverse the collider array and any collider with the gameObject tag of "Invisible Platform" would turn their render On and after time would go back to invisible.
The issue I'm having is after debugging i noticed that the Physics.OverlapSphere has 0 entries even though a 2D box collider is placed right next to the player and it doesn't seem to register it. I played around with the radius and and Physics.OverlapSphere but nothing worked. Any help?
// Start is called before the first frame update
public float radius;
private Vector3 centre;
public bool platformIsOn = false;
private float show;
void Start()
{
gameObject.GetComponent<Renderer>().enabled = false;
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.B))
{
centre = GameObject.FindGameObjectWithTag("Player").transform.position;
HocusPocuse(centre, radius);
}
}
void HocusPocuse(Vector3 center, float radius)
{
Collider[] hitColliders = Physics.OverlapSphere(center, radius, 0);
Debug.Log(Physics2D.OverlapCircle(centre, radius, 0));
for (int i = 0; i < hitColliders.Length; i++)
{
Debug.Log("HocusPucse has started");
if (hitColliders[i].gameObject.CompareTag("InvisiblePlatform"))
{
hitColliders[i].gameObject.GetComponent<Renderer>().enabled = true;
show = Time.time + 1f;
}
}
}