Search Unity

Resolved Identify Collider when there are 2 on same GameObject

Discussion in 'Scripting' started by larswik, Nov 29, 2022.

  1. larswik

    larswik

    Joined:
    Dec 20, 2012
    Posts:
    312
    Hey, I have a space shooter and I attached a auto gun to the side of my ship, photo included. I added a Collider that is a Trigger for the boundary of the gun to activate, photo also included. It works great as is now, but now I want to add that auto gun to the other side of the ship. I want to set up the another gun on the opposite side with another collider.

    The issue I had at first was where to add the collider. I first put it on the gun that is a child object of the ship, but the gun rotates as I use a LookAt() and that caused the collider to rotate too. So I moved the collider to the parent ship GameObject. I adjusted to code so that OnTrigger happens on the parent and sends a message to the gun script on the child to start shooting. But now I want to add a second Collider to the parent ship for the other side and can't find a way to distinguish between which Collider has been triggered. The only info that I get from the collision is the other object, which is to be expected. Any help is much appreciated.
     

    Attached Files:

  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    Just put it on a separate child object. Not the parent, not the rotating turret. Just another object colocated with the turret.
     
  3. larswik

    larswik

    Joined:
    Dec 20, 2012
    Posts:
    312
    Ahh. a simple solution, thank you!