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

How to interact with only one of the objects with the same tag at a time in a Trigger?

Discussion in 'Scripting' started by Amras789, Mar 4, 2020.

  1. Amras789

    Amras789

    Joined:
    May 4, 2019
    Posts:
    3
    I am coding a game where the player interacts with people. In the beginning all the people have the same tag. When the player is in the Trigger around the person and presses E it opens a menu to choose what job they should perform. A problem comes in when there are two or more people in the same area so all of them get the same job.

    I tried making a list of the colliders and just pulling the [0] and interacting with it but couldn't get that to work because it was literally adding just the Collider component.

    is there a way to prosses them one at a time? Or is there a better way of doing this than with trigger colliders?
     
  2. Serinx

    Serinx

    Joined:
    Mar 31, 2014
    Posts:
    785
    you could use raycasting to assign jobs to the person you're looking at rather than the person you're close to.

    Sort of need more details about the game before I can suggest anything useful.

    Is it first person? third person? birds eye view?

    A screenshot might help.
     
    Amras789 likes this.
  3. Amras789

    Amras789

    Joined:
    May 4, 2019
    Posts:
    3

    I have no clue why I didn't think of this already *facepalm

    I just tried this and it works perfectly!
    Thanks a ton for such a fast reply!
     
    Serinx likes this.