Search Unity

Collision detection not working

Discussion in 'Scripting' started by chemsoun, May 26, 2015.

  1. chemsoun

    chemsoun

    Joined:
    Apr 9, 2015
    Posts:
    49
    hi

    i have a charachter in my scene that should collide with other GO in the scene. i attached my script to the character and added a Box Collider to it with the Is Trigger checked, i also added a Rigidbody component to the character, and for the GO i added a box collider to every one without checking the Is Trigger, this should work as i thaught but it didn't, no collision is detected.

    that's my script

    Code (CSharp):
    1. void OnTriggerEnter(Collider col){
    2.  
    3.         if (col.gameObject.tag == "aliment") {
    4.        
    5.             Destroy(col.gameObject);
    6.             Debug.Log(col.gameObject.name);
    7.         }
    8.  
    9.     }
     
  2. Chaselon

    Chaselon

    Joined:
    May 17, 2015
    Posts:
    13
    It works fine on my end when I tested it, did you make sure the tag names were the same between what is in the script and what the gameObject has?
     
  3. Josenifftodd

    Josenifftodd

    Joined:
    Nov 29, 2013
    Posts:
    158
    Remember to add tags to objects or it wont work...