Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by macintosh_HD · Mar 01, 2014 at 05:07 PM · triggertriggers

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!

Comment
Add comment · Show 7
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image robertbu · Mar 01, 2014 at 05:11 PM 0
Share

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.

avatar image macintosh_HD · Mar 01, 2014 at 06:18 PM 0
Share

thank you for comment. The 'isTrigger' checkbox is checked on every collider I used. I will try the OnCollisionEnter() function.

avatar image highpockets · Mar 01, 2014 at 07:10 PM 0
Share

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;
avatar image Dizmiester · Mar 01, 2014 at 07:11 PM 0
Share

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..

avatar image highpockets · Mar 01, 2014 at 08:56 PM 1
Share

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.

Show more comments

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Using triggers to repeat basic scenes 1 Answer

Glitchy Turret Script 2 Answers

Trigger doesn't work 100% of the time. 1 Answer

Does OnTriggerStay don't detect a collision with a non-trigger collider? 1 Answer

Problems with the Trigger Collider (randomly fictional) 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges