How can i perform OverlapSphere for parallel arrays which detect when there is a overlapping of prefab gameObjects ?
Here is my code which generates these prefabs in random positions and sizes.
Okay, so using an OverlapSphere to solve your problem is probably not going to work. This is simply because the OverlapSphere is a sphere, while your platforms are (probably rectangular) boxes. So if you have two long platforms that’s just over each other, a sphere will detect them as “collided”, even though they’re not.
So, as long as you don’t have very many platforms, the easiest thing will be to check each new platform against every other, to see if their bounds overlap. This will get very slow very fast if you’re trying to do it with many platforms, though.
platformPrefabPosition_.y = posY*; platformPrefabPosition.z = posZ;_ _GameObject newPlatform = Instantiate(platformPrefab, platformPrefabPosition, Quaternion.identity) as GameObject; //fixed a bug here, don’t change the scale of the prefab, change the instantiated object instead* newPlatform.transform.localScale = new Vector3(scaleX*, 1, 1);* Collider newPlatformCollider = newPlatform.collider; bool overlaps = false; foreach (Collider c in platformColliders) { if (c.bounds.Intersects(newPlatformCollider.bounds)) { overlaps = true; } } if (overlaps) { //You’ve detected overlapping! Congratulations! } else { platformColliders.Add(newPlatformCollider); } } So if you want to remove overlapping platforms, you just do Destroy(newPlatform); under if(overlaps). Now, as I said, this will be fine with 10-20 or even maybe more platforms, but since you’re checking the bounds of every platform against the bounds of every other platform, for 100 platforms that’ll get you in the vicinity of 10.000 checks, and you’ll probably need to look for something else._