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

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,725
    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!