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

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

Triggers? How do I use them to finish a game? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges