Search Unity

Issue with OnTriggerEnter()

Discussion in 'Scripting' started by admiralelf, Aug 3, 2020.

  1. admiralelf

    admiralelf

    Joined:
    Mar 20, 2019
    Posts:
    3
    I'm fairly new to unity and am basically just learning the simple stuff, sorry in advance if this is a dumb mistake, and for the inevitable formatting errors.

    I have a player in a 2d game, that will walk over a flower that has a Box Collider 2d with IsTrigger checked, and then the following script on the player object should send a message to let me know the player collided with the trigger


    using UnityEngine;

    public class Itempickupchecker : MonoBehaviour
    {
    void OnTriggerEnter(Collider other)
    {
    Debug.Log("Flower picked up");
    }

    }


    however when the player walks over the flower nothing happens. The collider on the flower is this:
    upload_2020-8-3_18-23-24.png
    and the colliders on the player are these:
    upload_2020-8-3_18-24-22.png

    I think the issue is either a typo, something wrong with the colliders/rigidbody or me using some function or component meant for a 3d game perhaps, but im not really too sure

    thanks for any help
     
  2. Deleted User

    Deleted User

    Guest

    Are they both on the same layer?
     
  3. admiralelf

    admiralelf

    Joined:
    Mar 20, 2019
    Posts:
    3
    I believe so, if i make the flower's collider not a trigger then the player can bump into it and stand on it etc
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,686
  5. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    You need to use OnTriggerEnter2D
     
    Kurt-Dekker likes this.
  6. admiralelf

    admiralelf

    Joined:
    Mar 20, 2019
    Posts:
    3
  7. Deleted User

    Deleted User

    Guest