- Home /
Problem with multiple triggers
Hi I'm writing a little game for an english project at school. So it's a simple roll-a-ball-game. In the game I have got some platforms where the User can jump on. each of the platform has got a name tag and a trigger-zone. But only the first trigger seems to work. where is the problem?
function OnTriggerEnter (tri : Collider)
{
Debug.Log("Ball in Collider: " + tri.collider.name + " ");
switch(tri.collider.name)
{
case "PoleInformation" :
Debug.Log("Ball enters Trigger: " + tri.collider.name);
PoleTag.gameObject.active = true;
triggered = true;
labelText = poleText.text;
break;
case "EuropeInformation" :
Debug.Log("Ball enters Trigger: " + tri.collider.name);
EuropeTag.gameObject.active = true;
triggered = true;
labelText = europeText.text;
break;
case "AmericaInformation" :
Debug.Log("Ball enters Trigger: " + tri.collider.name);
AmericaTag.gameObject.active = true;
triggered = true;
labelText = americaText.text;
break;
case "AsiaInformation" :
Debug.Log("Ball enters Trigger: " + tri.collider.name);
AsiaTag.gameObject.active = true;
triggered = true;
labelText = asiaText.text;
}
}
Thank you for your help!
Don't see anything wrong with the code. Are you sure that 'isTrigger' is set on the other colliders? You might also put an OnCollisionEnter() in the script and output the name of the object the ball is colliding with to see if some other collider is blocking the trigger.
thank you for comment. The 'isTrigger' checkbox is checked on every collider I used. I will try the OnCollisionEnter() function.
Are you looking for the "tag" name or the name in the heirarchy?? If all the platforms are named the same in the heirarchy, I think your probably getting the same debug.log output. If you want to get the tag, ins$$anonymous$$d of:
tri.collider.name;
Use:
tri.collider.gameObject.tag;
tri is a Collider type object, so wouldn't you be able to just reference it's name variable with tri.name? Also is triggered a global variable? does it get set to false by an OnTriggerExit() function. Other wise it would be true on the first trigger and not get set again to false, which in turn would not allow other triggers to set it to true in the OnTriggerEnter()? $$anonymous$$y first go at answering questions on here so let me know if it helps..
You can enter multiple triggers within other triggers and they continue to be called. It is not a variable that gets set to true and false, but rather an event that is sent on entering, staying, exiting. If you were in 2 triggers at once, they would both output OnTriggerStay for instance.
Your answer
![](https://koobas.hobune.stream/wayback/20220613135112im_/https://answers.unity.com/themes/thub/images/avi.jpg)