0

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

  • Are the colliders touching/overlapping or really just adjacent? If they overlap right away, `OnCollisionStay` would probably be the better on, but I'm not sure this is a practical solution overall. – Gunnar B. May 25 '16 at 12:56
  • I think some sort of graph would be better for this. – Gunnar B. May 25 '16 at 12:59
  • Does at least one of your objects have a RigidBody attached to it? There's not currently enough information supplied for us to properly assist you. (It'd just become a guessing game of probable causes...) – Serlite May 25 '16 at 14:19
  • @Serlite That's actually a thing that came to my mind too. At least every other part of the chain would have to have a rigidbody. I don't know how many of those detection sections you have, but if it's some you will probably get performance issues. – Gunnar B. May 25 '16 at 15:52

1 Answers1

0

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