I am currently creating a randomly generated road in Unity. The road itself works exactly as intended, but now the collision becomes the tricky part.
My road is made of square tiles, and I want the player to walk on the interior. What I have done is I set up for separate Box Collider 2D to the prefab which create the cubes in this road.
What I want to do is have each of the tiles check for if there’s a tile to any given side of, and if there is, then disable the respective Box Collider 2D based on that. If there is another tile to the direct left and to the direct right of one tile, it will disable its Box Colliders that lie on the left and right sides. If one detects a tile above and to the right of itself, it will disable the top Box Collider 2d as well as the right, and so on.
Th two major questions here are:
-
How can I do a check of if another object is within proximity (in this case basically touching it) within the script?
-
How can I individually turn off Box Collider components on a prefab, rather than the whole lot of them?
Thanks a bunch!