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

void OnTriggerEnter2D(Collider2D collisionObject) not working with drag object to the trigger

Discussion in '2D' started by karammaks, May 5, 2015.

  1. karammaks

    karammaks

    Joined:
    Apr 6, 2014
    Posts:
    146
    Hi
    i am creating 2D game to drag letters and put them in the right order or place and make some action when put them in the correct order like sound .Anyway , i am using trigger so when i drag the letter to that trigger, it should give me that sound, but it doesn't. unless i use Rigidbody 2D property the letter (which i dont want to use Rigidbody).

    this is the code i use for the trigger:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class GameTrigger1_1 : MonoBehaviour {
    5.     public AudioClip au;
    6.         public void OnTriggerEnter2D(Collider2D collisionObject){
    7.         if (string.Equals (collisionObject.tag, "D")) {
    8.                     audio.PlayOneShot(au);
    9.                 }                  
    10.    
    11.         }
    12.    
    13. }
    i already give the letter BoxCollider 2D property, and i dont know its not working and give me any output while i drag the letter to the trigger, looking for your help

    thanks
     
  2. DrowningFish

    DrowningFish

    Joined:
    May 6, 2015
    Posts:
    12
    I'm not pro, but just giving my 2 cents, did you tick the checkbox for isTrigger for your collider?
    Also, to see if it is actually colliding, try using debug.log ("test message") in your code.