Search code examples
objectunity-game-enginegridtilecollider

Get adjacent objects (tiles) using Colliders? (Unity)


I'm trying to make a script for every section of cable that detects adjacent cables through colliders. I'm making it with colliders because there are mechanisms such as switchers and I think it's easier by this way to detect which path the "light" has to follow.

I've tried this code but didn't work and no gameobject is added to the List:

 public class cable : MonoBehaviour {
     List<GameObject> connections = new List<GameObject>();
     void OnCollisionEnter(Collision col) {
         connections.Add(col.gameObject);
     }
 }

Here you have a image of how it looks: enter image description here


Solution

  • Finally, I solved this long time ago. I used exact coordinates instead of colitions.