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 Hyperactive · Feb 05, 2015 at 02:17 PM · gameobjectcolliderontriggerentertag

Trigger when 3 triggers collide.

Hi All,

I'm trying to do something really simple, trying to get something to happen when 3 or more triggers collide.

Let's say I have a main trigger A, and then 2 other triggers B and C. If B collides with A alone, nothing happens. If C collides with A alone, nothing happens. If B & C both collide with A (at the same time or one after the other, as long as they are colliding together at some point), I would like this to make something happen.

So I tag both of the colliders and try this script (which I put on A) but it doesn't work...

   void OnTriggerEnter(Collider other) {
 {
 if (( other.gameObject.tag = "B") && ( other.gameObject.tag = "C"))
 }
         Do This();
     }

Is this because "Collider other"is only reference to one object, and not two ?

Thanks !

Hyper

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

1 Reply

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by carrollh · Feb 05, 2015 at 02:35 PM

Try this instead. (I fixed your curly braces and boolean checks).

     bool collidingB = false;
     bool collidingC = false;
 
     void OnTriggerEnter(Collider other) {
          if ( other.gameObject.tag == "B" ) collidingB = true;
          else if( other.gameObject.tag == "C" ) collidingC = true;
 
          if( collidingB && collidingC ) {
               Do This();
          }
     }
 
     void OnTriggerExit(Collider other) {
          if(other.gameObject.tag == "B") collidingB = false;
          else if(other.gameObject.tag == "C") collidingC = false;         
     }
 

Comment
Add comment · Show 9 · 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
avatar image chariot · Feb 05, 2015 at 02:52 PM 0
Share

Why disvoted? Good solution, why not

avatar image carrollh · Feb 05, 2015 at 02:54 PM 0
Share

They hit it before my first edit. I was just fixing the typos in the question. $$anonymous$$y edit actually answered the root problem (after clearing the syntax errors of course ;)

avatar image Hyperactive · Feb 05, 2015 at 02:56 PM 0
Share

Seems like a good answer ! Thanks a lot. Gonna try it out now and I'll let you know :) Btw, I don't think boolean works does it ? Thought it was just bool...

avatar image Hyperactive · Feb 05, 2015 at 02:58 PM 0
Share

Also... What's the reason why my example doesn't work ? :) I could just move on, but I like to understand why it doesn't work at all.

avatar image carrollh · Feb 05, 2015 at 02:59 PM 0
Share

You're right. I can't keep them straight between C#, js, and java. And I'm not in an IDE so no backup :P

Edited my script. Thanks. Let me know how it goes.

Show more comments

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

21 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

Related Questions

Is CompareTag faster than checking directly the GameObject? 1 Answer

Collision Detection without a RigidBody 2 Answers

Raycast starts ignoring gameobject after a few seconds 0 Answers

Can I use OnTriggerEnter with one tag for multiple objects? 0 Answers

Why isnt OnTriggerEnter Tags working. 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