- Home /
 
 
               Question by 
               dijital · Jun 02, 2013 at 10:24 AM · 
                collidertriggercollidersontriggerenterontriggerexit  
              
 
              Make object react to certain triggers only
Hi, I have a scene with two different triggers attached to box colliders, one changes the gravity force and the other changes the angular drag of the player.
The problem is, when I hit any of the triggers, it changes both the gravity and the drag.
How in code do I get it to differentiate between the triggers? I thought I was by naming the box colliders and calling them in the script like below, but that doesn't seem to work.
     function OnTriggerEnter (DZone : Collider) {
         rigidbody.angularDrag = 0.4f;
         print("DRAG LOW DRAG LOW");
     }
     
     function OnTriggerExit (DZone : Collider) {
         rigidbody.angularDrag = 25.0f;
         print("DRAG HIGH DRAG HIGH");
     }
 
               Any help would be appreciated.
Thanks!
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by fueldown · Jun 02, 2013 at 10:59 AM
You should compare the tags in order to differentiate between them.
     function OnTriggerEnter (DZone : Collider){
         if(DZone.tag == "TagOfObjectYouWantToReduceDragOF"){
            rigidbody.angularDrag = 0.4f;
            print("DRAG LOW DRAG LOW");
         }
     }
      
     function OnTriggerExit (DZone : Collider) {
         if(DZone.tag == "TagOfObjectYouWantToIncreaseDragOF"){
            rigidbody.angularDrag = 25.0f;
            print("DRAG HIGH DRAG HIGH");
         }
     }
 
              use DZone.rigidbody.angularDrag
ins$$anonymous$$d of
 rigidbody.angularDrag
 
                 Glad I could help. $$anonymous$$ake sure you mark it as an accepted answer if you think the issue is resolved.
Your answer