- Home /
 
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)
 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?
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");
     }
                  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. 
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.
Your answer
 
             Follow this Question
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