- Home /
How to enable/disable "Is Trigger" on collision enter ?
Hi
I want to enable "Is Trigger" if the enemies hit each other and disable it if they hit the player. so the player can die.
i think "on collision enter" will do it but i can't handle the scripting stuff
Answer by Meater6 · Mar 26, 2011 at 02:18 PM
Tag all the enemies "Enemy" and tag the player as "Player". Then use this script:
function OnCollisionEnter(collision : Collision) { if(collision.transform.tag == "Enemy" && !transform.collider.isTrigger){ transform.collider.isTrigger = true; } }
function OnTriggerEnter(trigCollision : Collider){ if(trigCollision.transform.tag == "Player" && transform.collider.isTrigger){
transform.collider.isTrigger = false; } }
I hope this helps. :)
I would like if you up voted this, if it is very helpful.
Answer by quinnbot · Jul 01, 2015 at 05:44 PM
Super old thread but I thought I'd point out the Physics Collision Matrix which does exactly what you need here without any scripting
Answer by Unamine · Mar 26, 2011 at 02:09 PM
Try using GetComponent to activate and deactivate the properties of a GameObject
Steps:
1 - Create a variable to identify the gameObject may be through the object tag
2 - Create another variable that is looking for a component within the previous variable
3-and enable or disable the property IsTrigger of the component.
Your answer
![](https://koobas.hobune.stream/wayback/20220613114956im_/https://answers.unity.com/themes/thub/images/avi.jpg)