Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Detect which collider trigger occured

Discussion in 'Scripting' started by TheCelt, Aug 7, 2016.

  1. TheCelt

    TheCelt

    Joined:
    Feb 27, 2013
    Posts:
    724
    Hello

    I have a game object with two sphere colliders one which is large and one much smaller.

    As a character enters each one i want different behavior to occur, but i don't know how to check which collider was triggered given depending on direction of travel the larger collider might not trigger if it is attacked from behind.

    Is there a unique id system for box colliders at all that can be passed to on trigger enter / exit?

    If not how can i do something like it? As unity really needs such a system in place!
     
  2. GNGification

    GNGification

    Joined:
    Oct 24, 2013
    Posts:
    59
    Im not actually sure if there is a way for that, I guess one way could be using a child and giving it a separate collider.

    Why dont you simply calculate the distance between object a and b?
     
  3. passerbycmc

    passerbycmc

    Joined:
    Feb 12, 2015
    Posts:
    1,739
    just put the colliders on multiple game objects
     
  4. TheCelt

    TheCelt

    Joined:
    Feb 27, 2013
    Posts:
    724
    Ok i'll use child game objects, kinda frustrating as that means more scripts to manage and connect on start/awake !
     
  5. passerbycmc

    passerbycmc

    Joined:
    Feb 12, 2015
    Posts:
    1,739
    make a script that, just has some UnityEvents that it fires off, when stuff hits its collider, than put this a a component on all your colliders. Than after that you can add methods from 1 script as the listeners to the colliders UnityEvents.