Author Topic: getting the Territory that is associated with a Cell in script  (Read 364 times)

yan

  • Newbie
  • *
  • Posts: 8
    • View Profile
how do I access the territory associated with a cell in 3D space in script? I tried doing:

Code
cellCenter = tgs.CellGetPosition(cellIndex);
Vector3 cellCenterInLocalSpaceOfTerrain = terrain.transform.InverseTransformPoint(cellCenter);
Vector2 cellCenterV2 = new Vector2(cellCenterInLocalSpaceOfTerrain.x, cellCenterInLocalSpaceOfTerrain.z);
tgs.TerritoryGetAtPosition(cellCenterV2)
...but figured tgs.TerritoryGetAtPosition() is only meant for 2D maps, since it was returning empty (not null). Is there something similar for 3D space or another way to get the territory that is associated with a cell or vice versa?

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 4994
    • View Profile
Re: getting the Territory that is associated with a Cell in script
« Reply #1 on: March 21, 2019, 11:38:51 PM »
Hi,
Each cell object has a territoryIndex field:

Code
Cell cell = tgs.cells[cellIndex];
int territoryIndex = cell.territoryIndex;

Or even simpler:

Code
int territoryIndex = tgs.CellGetTerritoryIndex(cellIndex);

Regards



yan

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: getting the Territory that is associated with a Cell in script
« Reply #2 on: March 24, 2019, 09:52:34 AM »
Excellent! Thanks!