Search Unity

Question How can I identify neighboring provinces?

Discussion in 'Editor & General Support' started by TurkishYSF, Feb 13, 2024.

  1. TurkishYSF

    TurkishYSF

    Joined:
    Jun 11, 2022
    Posts:
    1
    I am developing a turn-based strategy game and am currently working on the attack system. I need to identify neighboring provinces to allow my soldiers to move between them. Given the large number of provinces in my game, manually attaching neighboring provinces one by one is very difficult. The provinces are named in a sequence, such as "province1", "province2", etc., and each has a polygon collider. Below are some images from my game and the map for better understanding:
    Screenshot 2024-02-13 190405.png
    Screenshot 2024-02-13 190448.png

    If my explanation is not clear yet, here is an image of my previous manual system for attaching provinces:
    Screenshot 2024-02-13 190901.png

    With this manual system, I attach provinces one by one, and my script prefixes the number with "province", resulting in string values like "province2", "province9", etc., which correspond to the naming of province objects. However, as I plan to add more provinces, this manual method will become increasingly cumbersome.

    How can I automatically detect neighboring provinces through a script? Or should I consider using a different system for managing provinces? Any advice or suggestions would be greatly appreciated.