Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

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);