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

ontriggerexit2d isnt working

Discussion in 'Scripting' started by verderveremem, Jul 2, 2014.

  1. verderveremem

    verderveremem

    Joined:
    May 11, 2014
    Posts:
    52
    hi all,

    i gave a tag to the prefabs which are being instantiated during the game, and i am using debug.log when my maingameobject touch the collider of these prefabs. Debug.log is working when ontriggerenter2d but its not working for the ontriggerexit2d. Can u guys help me please
    Code (CSharp):
    1. void OnTriggerEnter2D(Collider2D col)
    2.     {
    3.        
    4.         if (col.gameObject.tag=="prefab")
    5.         {
    6.             Debug.Log("touching");              
    7.  
    8.            
    9.         }    
    10.      
    11.        
    12.        
    13.     }
    14.  
    15.     void OnTiggerExit2D(Collider2D col)
    16.     {
    17.         Debug.Log("left the area");
    18.     }
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    are you destroying the things you are expecting to trigger the exit function?

    how are you moving things?
     
    verderveremem likes this.
  3. verderveremem

    verderveremem

    Joined:
    May 11, 2014
    Posts:
    52
    i want to destroy my main gameobject when ontriggerexit2d happens. And i am controlling my main gameobject by dragging it
     
    Last edited: Jul 2, 2014
  4. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    direct position update, translate function.. addforce?
     
  5. verderveremem

    verderveremem

    Joined:
    May 11, 2014
    Posts:
    52
    i have no idea what you re sayin. i just need help with working properly the ontriggerexit2d function.
     
  6. verderveremem

    verderveremem

    Joined:
    May 11, 2014
    Posts:
    52
    help me please guys, i still dont solve the problem
     
  7. Spinami

    Spinami

    Joined:
    Jul 2, 2014
    Posts:
    1
    I see a typo in OnTiggerExit2D, it should be OnTriggerExit2D, missing an r.
     
    verderveremem likes this.
  8. verderveremem

    verderveremem

    Joined:
    May 11, 2014
    Posts:
    52
    thank you