Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 SSpecks · Mar 06, 2020 at 06:32 PM · collidertriggercollidersontriggerenterbox collider

How to use different and distinguish between different box colliders?

I have a game object with two box colliders attached, one to see the player and one to end the game. The player also has a box collider attached. //the box colliders public BoxCollider collider1; // longer box collider (trigger) public BoxCollider collider2;//smaller box collider (trigger)alt text public BoxCollider colliderPlayer; //player box collider

 private void OnTriggerEnter(Collider collider1) //when the box collider is seen
     {
         Debug.Log("i see you"); //play a sound?
         StartCoroutine("VisibilityTime");
     }
 
     private void OntriggerEnter(Collider collider2)
     {
         Debug.Log("touch");
     }

I do not know how to distingwuish between the box colliders AND the second onTriggerEnter is never used for some reason?

screenshot-9.png (141.7 kB)
Comment
Add comment · Show 3
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 Frosh1 · Mar 06, 2020 at 06:51 PM 0
Share

What are you trying to archive?

avatar image SSpecks Frosh1 · Mar 06, 2020 at 07:58 PM 0
Share

I don't know what you mean by archive, i'm just wanting to have the colliders be distinguishable so i can use my code (ive tried changing the code to this and it is still not working

 public BoxCollider collider2;//seeing one
     public BoxCollider colliderPlayer;
     private void OnTriggerEnter(Collider collider1) //when the box collider is seen
     {
        
         
         if (gameObject.CompareTag("Player"))
         {
             Debug.Log("touch");
         }
     }
 
     private void onTriggerEnter(Collider collider2)
     {
         StartCoroutine("VisibilityTime");
     }

avatar image JPhilipp · Mar 06, 2020 at 09:16 PM 0
Share

You can't use multiple OnTriggerEnter functions in your same gameObject (and you can't spell one "OntriggerEnter", that will simply have it be ignored). Ins$$anonymous$$d, either use a special tag that you check for, or attach a special component class (or class property) to them and use GetComponent when it triggers.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by BBIT-SOLUTIONS · Mar 08, 2020 at 10:26 PM

You can't distinguish them, when they are assigned to the same GameObject.

Easiest way to solve is probably using a second GameObject for your EndGameTrigger and make it a child of the player. Then only assign a box collider (marked as trigger) and use a new Script with a separate OnTriggerEnter() method for it.

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.

Follow this Question

Answers Answers and Comments

182 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 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Problems with the Trigger Collider (randomly fictional) 1 Answer

Make object react to certain triggers only 1 Answer

Can it be detect several colliders in the same gameObject? 0 Answers

Trigger and Collider Issues 1 Answer

Application.LoadLevel ("lower") loads on start-up, not when triggered; Deadline is soon HELP! 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