- Home /
Multiple OnTriggerEnter on One Collider
I have been having issues with implementing a couple of scripts that both require to use the OnTriggerEnter function on the same collider. These two OnTriggerEnter commands are both located in different scripts however when both are referring to same object either one or the other does not work. Is this even possible and / or is there a work around I could use in this situation?
Excerpt from Script One:
function OnTriggerEnter (other: Collider){
if(other.gameObject == playerObject && !hitCoolDown){
playerState.playerHealth -= damageDone;
hitCoolDown = true;
}
}
Excerpt from Script Two:
function OnTriggerEnter (other : Collider){
if(other.tag == "CollectPickaxe"){
canPickupPickaxe = true;
}
if(other.tag == "CollectFlareGun"){
canPickupFlareGun = true;
}
if(other.tag == "CollectRadMeter"){
canPickupRadMeter = true;
}
}
Two questions: 1: Did you test them separately?
2: You mention OnCollisionEnter yet the code shows OnTriggerEnter, Did you check the "Is Trigger" for the colliders? Because that's what OnTriggerEnter is for.
and one more thing: you have written only part of code, so it's not clear. Does the execution order of thees OnTriggerEnter methods matter to your scripts? Could wrong order break something?
Apologies I was quite exhausted when I wrote this, it was meant to say OnTriggerEnter
I have more code to the scripts but they work independently but not in combination.
The Tool script I wrote a while back and it has been working consistently until now.
Answer by Razputin · Feb 04, 2015 at 01:38 AM
I asked a question like this a while back.
http://answers.unity3d.com/questions/650176/how-to-do-multiple-ontriggerenters.html
maybe this helps a little?