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. Dismiss Notice

Most efficient way to check the tag of adjacent Gameobject (other than collision)

Discussion in 'Scripting' started by NidoAnxari, Jun 16, 2017.

  1. NidoAnxari

    NidoAnxari

    Joined:
    Jan 2, 2017
    Posts:
    86
    Is there any other way to check the tag of gameobject adjacent to another gameobject. I don't want to use colliders because there will be so many gameobjects.
     
  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Depends.. You could raycast if you knew the direction for sure.
    If you set them up (know their positions, etc.) you could use that information to know what's nearby.

    Could you describe your game a bit , including the use of getting/knowing the tag? That might help anyone reading to offer better advice.
     
  3. NidoAnxari

    NidoAnxari

    Joined:
    Jan 2, 2017
    Posts:
    86
    It is bubble shooting match three game.
    Idea I came up last night was to check if the object next to another object is of same color. If so, then add it in a list. After that check the list if is larger than three. If so then destroy each Gameobject in it and also empty the list.
    How is this idea?
     
  4. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    so like.. just checking - this is grid-like?
     
  5. NidoAnxari

    NidoAnxari

    Joined:
    Jan 2, 2017
    Posts:
    86
    But I want to do it without colliders.
     
  6. NidoAnxari

    NidoAnxari

    Joined:
    Jan 2, 2017
    Posts:
    86
    No.
     
  7. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Yes, I read the part about not wanting colliders.

    For future reference, if you want to make additions quickly after your post, it would be maybe better to edit your post, optionally just writing a newline and "Edit: <whatever your new stuff is here>" :)
     
    NidoAnxari likes this.
  8. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    so the bubbles can be anywhere? they're not restricted like in a grid(that's what my question meant when I asked/said "Grid-Like")
    How many objects can you possibly have to think that colliders won't be good? Just curious.
     
  9. NidoAnxari

    NidoAnxari

    Joined:
    Jan 2, 2017
    Posts:
    86
    I think there will be 30 to 40 objects.
     
  10. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    oh man, don't worry about that.. that's not too much. Colliders can work for you no problem.
     
    NidoAnxari likes this.
  11. NidoAnxari

    NidoAnxari

    Joined:
    Jan 2, 2017
    Posts:
    86
    Thanks... I was worried because in some other thread a guy told about not to use them. But now I think it will be more than okay to use them☺
     
  12. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Yeah, I think it won't be a problem. If I had a better grasp of the type of game you were describing I could offer other ideas, for your consideration.. (they wouldn't necessarily be better, mind you.. ). Since I can't quite picture the game you're aiming for, I can't really do that.
    Anyways, since I'm sure you'll be okay.. You should proceed with colliders and check 'em ;)
    Enjoy your game!
     
  13. NidoAnxari

    NidoAnxari

    Joined:
    Jan 2, 2017
    Posts:
    86
    Thanks a lot brah☺
     
  14. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    You're welcome :)
     
    NidoAnxari likes this.
  15. steego

    steego

    Joined:
    Jul 15, 2010
    Posts:
    967
    If you end up not wanting to use collisions for this, the most efficient solution is probably using a quad-tree (or oct-tree if in 3D). But for just 40-50 objects, I agree using colliders or just iterating over an array is probably good enough™.
     
    NidoAnxari likes this.