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. Dismiss Notice

2D OnTriggerEnter?

Discussion in '2D' started by aidenkael, Apr 10, 2014.

  1. aidenkael

    aidenkael

    Joined:
    Mar 10, 2013
    Posts:
    33
    I have a rigidbody attached to my player, and no rigidbody attached to the powerups. This script is attached to the powerups:
    Code (csharp):
    1. void OnTriggerEnter(Collider col)
    2.     {
    3.         Debug.Log("A trigger was hit");
    4.     }
    When I collide with the powerups nothing is written to the console. Do I need to use OnTriggerEnter2D?
     
  2. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    Yes.

    Code (csharp):
    1.  
    2. void OnTriggerEnter2D (Collider2D col)
    3.     {
    4.         Debug.Log ("A trigger was hit");
    5.     {
    6.  
     
  3. aidenkael

    aidenkael

    Joined:
    Mar 10, 2013
    Posts:
    33
    Changed to that but no luck. Nothing happens again.
     
  4. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    Do both objects have colliders?
    Are the colliders sized correctly?
    Is at least one collider a trigger?
    Is your rigidbody non-kinematic?
    Is your rigidbody active?
     
  5. aidenkael

    aidenkael

    Joined:
    Mar 10, 2013
    Posts:
    33
    I was using 3D colliders, and not 2D colliders. That was what was causing all my issues. Not much documentation on the difference between them, but it works now!
     
  6. unity_HxF9bz13Mt5zfw

    unity_HxF9bz13Mt5zfw

    Joined:
    Jun 13, 2018
    Posts:
    1
    What do you mean rigid body , I have attached 2D colliders to a line object , How do I make it rigid body
     
  7. barskey

    barskey

    Joined:
    Nov 19, 2017
    Posts:
    207
    Add a RigidBody2D component to your gameobject.
     
  8. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,802
    https://docs.unity3d.com/Manual/PhysicsSection.html
    https://unity3d.com/learn/tutorials/s/physics