Question by
hvd · Jan 29, 2016 at 06:20 PM ·
listindexcollission
find out list index of collided object ?
Hey,
i have a list of segments in my game and if my player collides with one of these segments i need to know which index this segment have? Any ideas how to do that ?
Comment
Best Answer
Answer by Jessespike · Jan 29, 2016 at 07:37 PM
public class ListOfSegments : MonoBehaviour {
public List<GameObject> Segments;
}
public class SomeColliderTrigger : MonoBehaviour {
public void OnTriggerEnter(Collider other) {
int index = FindObjectOfType<ListOfSegments>().Segments.IndexOf(this.gameObject);
Debug.Log(index);
}
}