Search Unity

OnTriggerEnter(Collider other) own collider?

Discussion in 'Physics' started by jordiboni, May 12, 2015.

  1. jordiboni

    jordiboni

    Joined:
    Aug 14, 2013
    Posts:
    26
    How can I get my collider when I collide with another BoxCollider? I have a plane with two BoxColliders and I need to know which collisioned with the other collider.

    collisionPlane.jpg
     
  2. Power07RM

    Power07RM

    Joined:
    Apr 22, 2015
    Posts:
    12
    One way is to attach a script to each of your colliders with OnTriggerEnter(Collider other) implemented. And when other collider triggers any of your box colliders simply Debug.Log(this.name); where this refers to the plane collider that detected the collision.
     
  3. jordiboni

    jordiboni

    Joined:
    Aug 14, 2013
    Posts:
    26
    With your reply I assume that for my plane I need a GameObjects structure like this:

    GameObjects.jpg
     
  4. Power07RM

    Power07RM

    Joined:
    Apr 22, 2015
    Posts:
    12
    Yeah. IsTrigger should be checked. Note that they will only be used as triggers, they will detect collision but they won't do anything apart from that. Now you should attach a script for example Detection.cs and in OnTriggerEnter(Collider other) call Debug.Log("Collider that detected collision is: " + name);