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

HELP! My OnTriggerEnter won't work :(

Discussion in '2D' started by deathmask, May 15, 2016.

  1. deathmask

    deathmask

    Joined:
    Mar 23, 2014
    Posts:
    4
    Help. I am a begginer and working on a simple 2D game, and this simple code won't work

    using UnityEngine;
    using System.Collections;
    public class DES : MonoBehaviour {

    void OnTriggerEnter(Collider other)
    {
    Debug.Log("enter");
    }
    }

    Both objects that I am trying to collide both have Rigidbody, and they both have colliders, the is trigger is checked on the object to which this script is attached.
    I am coding in C#.
     
    Last edited: May 15, 2016
  2. EnricoBC

    EnricoBC

    Joined:
    May 4, 2014
    Posts:
    20
    You forgot to specify the parameter for OnTriggerEnter, it should be void OnTriggerEnter(Collider other), see http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnTriggerEnter.html for more information.
     
    deathmask likes this.
  3. deathmask

    deathmask

    Joined:
    Mar 23, 2014
    Posts:
    4
  4. EnricoBC

    EnricoBC

    Joined:
    May 4, 2014
    Posts:
    20
    Can you post screenshots of your game objects showing the script and rigidbodies?
     
  5. deathmask

    deathmask

    Joined:
    Mar 23, 2014
    Posts:
    4
    Here they are, thank you again :D
    http://prnt.sc/b4av96
    http://prnt.sc/b4avpa

    The current state of the game is bad but it will be better once i figure out what the trigger problems are
    tnx
     
  6. EnricoBC

    EnricoBC

    Joined:
    May 4, 2014
    Posts:
    20
    Sorry, I'm not used to 2D on unity so I didn't realize there were different methods for colliders here, try changing your OnTriggerEnter to this:
    Code (CSharp):
    1. void OnTriggerEnter2D(Collider2D other)
     
    deathmask likes this.
  7. deathmask

    deathmask

    Joined:
    Mar 23, 2014
    Posts:
    4
    I solved it, Since
    THANK YOU :D
    That's the problem it works now!
     
    EnricoBC likes this.