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

Getting Collader

Discussion in 'Scripting' started by Van_G0gh, May 25, 2022.

  1. Van_G0gh

    Van_G0gh

    Joined:
    May 25, 2022
    Posts:
    3
    hello, tell me, is it possible to get this collider from an object that hit the collider in Unity?
    That is, Collider A collides with Collider B, and A gets information about Collider B.
    Sorry for the translation, I hope you understand what I mean.
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,735
    Yes the collision callbacks (OnCollisionEnter, OnTriggerEnter, OnCollisionEnter2D, OnTriggerEnter2D) all contain information about the other object in the parameters provided to the method.
     
    Van_G0gh likes this.
  3. Van_G0gh

    Van_G0gh

    Joined:
    May 25, 2022
    Posts:
    3
    Thanks for the help, but the question arose: Can OnTrigger work without a rigidbody ?
    I'm making a 2D game and don't use rigidbody
     
  4. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,735
    If you look at the charts at the bottom of https://docs.unity3d.com/Manual/CollidersOverview.html you will see the conditions under which trigger messages will be sent.

    Short answer is you need at least one Rigidbody. It can be kinematic though.
     
    Van_G0gh likes this.
  5. Van_G0gh

    Van_G0gh

    Joined:
    May 25, 2022
    Posts:
    3
    Okay, thanks for the help.