• 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 spaceduck_corp · Jun 19, 2014 at 07:34 AM · collidertrigger

Trigger reacts to multiple colliders not the object

 void OnTriggerEnter2D(Collider2D collider){
     if(collider.gameObject.CompareTag("Car")){
         LapManager.instance.Check(transform);
     }
 }

My car have one block collider and two circle colliders. The problem is that every of them triggers the script and what I want is to make trigger react to GameObject one time per touch. Is there a good way to make this? I was thinking about list of gameObjects that are inside trigger at the moment, so I'll check if gameObject is in the list already before actions. I hope there is a better way.

Comment
Add comment · Show 4
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 suribe · Jun 19, 2014 at 02:13 PM 0
Share

If I understand correctly, you want the trigger to fire when the first one collides, but ignore the others? Will the objects collide with this trigger again later? (like for counting laps)

avatar image spaceduck_corp · Jun 19, 2014 at 05:08 PM 0
Share

Exactly. Yeah it will collide that checkpoint on the next lap

avatar image KaPow1 · Jun 19, 2014 at 05:45 PM 1
Share

Could you modify your car object so that the block collider has a different tag than the two circle colliders? This way you could check for just one collider on collision (probably the block collider) by its tag and not worry about the two circle colliders.

[Edit] Alternatively, if you don't want to change the tags on your objects, you can check the name of the object you hit. For example, let's say your block colliders will always be attached to objects named "Car#" (where # is the number of the car), and your circle colliders will always be attached to objects named "wheel". You can do the following check in your code:

 if(collider.gameObject.name.Contains("Car"))
 

to ensure that only the car object will trigger the event.

avatar image spaceduck_corp · Jun 19, 2014 at 09:51 PM 0
Share

so basically, I added a child to my car and put circle colliders on it. As this child does not have tag "Car" it will not trigger my script. Thank you! It is very simple, but is better than modifying my script with list etc.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by BBoldenow · Jun 19, 2014 at 06:32 PM

Another way to do this is with layers. You can create a new layer for the trigger and collider. Then in your physics manager don't let this layer interact with any other physics layer. This will be more efficient as well since the trigger and collider aren't going to have to check against every other object in the scene.

http://docs.unity3d.com/Manual/LayerBasedCollision.html

Comment
Add comment · Share
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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Collider IsTrigger won't work correctly with close second Collider 0 Answers

Can't click gameobject when over another trigger? 1 Answer

OnTriggerEnter not being called with multiple colliders 1 Answer

Triggering platform animation on colliding with Button 0 Answers

Use trigger with player but have a collider with everything else? 3 Answers


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