2 Colliders on 1 gameobject

Hello,

I want to be able to have 2 colliders on a gameobject but both being affected by 2 different actions.

Meaning:

Imagine a circle in the air(with 2 circle colliders on). The first collider will be 5x bigger than the circle, the second collider being 2x bigger than the circle. Now if the player collides with the first circle, it will spawn a 'missile' that will fire at the circle and if that 'missile' collides with the second collider, it will destroy the circle and itself. How can i give a title to the two different colliders for the ability i am trying to do to function properly. Like giving that collider a tag or something.

I am 99% sure you could do this:

  1. Give your gameObject two empty child GameObjects
  2. Attach a different collider to each child object
  3. Write two scripts with your OnColliderEnter functions for each collider
  4. Attach each script to each child object

So in the end you would have:

-Parent GameObject with:

-Child A with Collider A (large collider) and Script A (missile spawning) attached

-Child B with Collider B (small collider) and Script B (destroy on collision) attached

What i would also consider is to create 1 script with 2 references (for each collider).
Afterwards, you could use:

GameObject  ChildGameObject1 = ParentGameObject.transform.GetChild (0).gameObject;
GameObject  ChildGameObject2 = ParentGameObject.transform.GetChild (1).gameObject;

Please check this out because I’m missing something

ChildObject 1 (small circle/collider)

void OnColliderEnter(Collision collision)
{
    
    char Lind = yellow_car.GetComponent<car_move1>().LcoinData;

    if(Lind == 'A'){

        yellow_car.GetComponent<car_move1>().LcoinData = 'B';
        Destroy(transform.parent.gameObject);

    }


}

ChildObject 2 (big circle/collider)

void OnColliderEnter(Collision collision)
{
    Debug.Log("CoinArea OK");
    if(Input.GetKeyDown(KeyCode.Space))
    {
    /*char Lind = yellow_car.GetComponent<car_move1>().LcoinData;

    if(Lind == 'A'){

        yellow_car.GetComponent<car_move1>().LcoinData = 'B';
        Destroy(gameObject);

    }
    */
    Debug.Log("shooting OK");
    }


}

Solved ! Thanks to everyone :slight_smile: