0

So, I am working on some level generation stuff in Unity, and I have some cubes spawning around the world. The way I have it working right now, is that each floor tile checks if there is 'air' around it and if so, it spawns a wall. But, if I have a situation where this is an air block between two floors, it'll spawn two walls. Is there a way I can check if there is multiple in the same position, but keep one from destroying? Thanks!

p.s Also worth nothing, I place the walls using Raycasts, so the floor will check in 4 directions using one hit. I figure it's checking all 4 directions without stopping when it places a cube. So, may be an issue...

Ben Lusted
  • 15
  • 3

1 Answers1

0

U can try making a overlapsphere where the raycast hits, that way all the objects in a certain radius get detected (so also objects that are in each other)

void GetWalls(Vector3 raycastTargetPosition, float radius)
    {
        Collider[] hitColliders = Physics.OverlapSphere(center, radius);
        int i = 0;
        while (i < hitColliders.Length)
        {
            hitColliders[i].SendMessage("AddDamage");
            i++;
        }
    }
Bean5 Music
  • 179
  • 4