Search Unity

OnTriggerEnter not work

Discussion in 'Scripting' started by pjl110, Apr 21, 2010.

  1. pjl110

    pjl110

    Joined:
    Mar 27, 2010
    Posts:
    20
    i put 2 gameobjects(A and B) in my scenes and set the component box collider.
    then i make A move forward B with script,and add the following script to B:
    Code (csharp):
    1.  
    2. function OnTriggerEnter (col : Collider)
    3. {
    4. print("sth in!");
    5. }
    6. function OnTriggerExit (col : Collider)
    7. {
    8. print("sth out!"); 
    9. }
    10. function Reset ()
    11. {
    12. collider.isTrigger = true;
    13. }
    14. @script RequireComponent(BoxCollider)
    15.  
    and i hope when the A entered B, CMD show:"sth in".
    but when my A entered.nothing happened.

    ps:
    1. i already add the box collider to A and B and set the B's Trigger checked!
    2. when my First Person entered B.CMD show "sth in!"correctly!

    why?!
     
  2. RickP

    RickP

    Joined:
    Apr 4, 2010
    Posts:
    262
    Any trigger that moves needs to have a RigidBody also to work correctly. Set the RigidBody to Is kinematic and uncheck use gravity.
     
  3. pjl110

    pjl110

    Joined:
    Mar 27, 2010
    Posts:
    20
    very thank you! :D :) :p