- Home /
Phyisics2D.OverlapCircleAll to detect walls
Hello
I'm making a game where I need a npc to wander in a set area defined by walls. Those walls can be added as the player progresses into the game. Since the 2 begining walls have a collider so that the npc can hit them, I've been trying to make it so that whenever a wall is set somewhere, the collider of all the walls in between the furthest walls turn off. I've tried Navmesh and raycast with no success. Now I'm trying Physics2D.OverlapCircleAll. Each wall will have this code. What it should do is check for colliders on the wall layer, if any is found then turn its own collider off. I'm also trying to make it so that the walls that have an x of 0 or greater check for walls with x 0 or greater and x of 0 or less check for walls with x of 0 or less. Here's my code below, I found most of it on this forum but it did not really anser my question. Also it seems that wallcol isnt recognized as a variable in the void detect
Any help would be greatly appreciated , thanks :3
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WallDetection : MonoBehaviour {
public BoxCollider2D wallcol;
// Use this for initialization
void Start () {
wallcol = GetComponent<BoxCollider2D>();
void detect(Vector2 center, float radius)
{
Collider2D[] hitColliders = Physics2D.OverlapCircleAll(center, radius);
int i = 10;
while (i < hitColliders.Length)
{
if (hitColliders[i].tag == "Walls")
{
}
i++;
}
Please take care to format pasted code with the 101010 button. This was done on your behalf.
I was unable to make sense of what you're trying to accomplish. Please read over the FAQ to see what our volunteers need to know to best assist you, and consider revising your question + adding a screenshot.
Cheers,