How do I prevent multiple triggers using OnTriggerEnter?

  • Object A has a trigger collider on
    it.
  • Object B has a trigger collider and a
    normal collider (not a trigger).

When Object A collides with Object B using OnTriggerEnter, the function produces 2 triggers. How do I detect only Object B’s normal collider?

OnTriggerEnter(Collider col) allows you to store a reference to the colliding gameObject/collider. Inside you can simply check if the collider is the one you want to detect and run your code based on that result.
For example:

void OnTriggerEnter(Collider col){
    if(!col.isTrigger){
        DoStuff();
    }
}

When doing it like this, DoStuff() is only executed when the colliding game object’s collider is not set to “isTrigger”. This is just an example. You can, of course, check for other properties to identify the object, like name or position.

Hope this helps.