Hello. So I made a list from Lands.cs, which populates with “imaginary” coordinates depending on terrain size. For example my terrain is size of 100. It makes 100 tiles with coordinates in Vector3, 1,1 , 0,1, etc.
So when my list is populated, I got a script depending on my mouse location, which gets the tile’s x and z(y in vector2 saved in list), and I am trying to find which tile is it (each tile has a different id) depending on those two coordinates in vector2. I am not sure how to use lists or linq for it, after I tried few things such as Find, Contains, Where, but I am not sure on how to do it.
My Lands.cs
[System.Serializable]
public class Lands {
public int landID;
public Vector2 tile;
public int ownerID;
public Lands(int id, Vector2 tile, int oID)
{
this.landID = id;
this.tile = tile;
this.ownerID = oID;
}
}
Scripts that finds the tile part:
if (GetComponent<Collider>().Raycast(ray, out hitInfo, Mathf.Infinity))
{
x = Mathf.FloorToInt(hitInfo.point.x / terrainTileSize);
z = Mathf.FloorToInt(hitInfo.point.z / terrainTileSize);
Debug.Log ("Tile: " + x + ", " + z);
currentTileCoord.x = x;
currentTileCoord.z = z;
// cube which displays which tile I am hovering on, imaginary
selectionCube.transform.position = currentTileCoord * terrainTileSize + new Vector3(terrainTileSize / 2 ,0 , terrainTileSize / 2);
// find tile in list depending on x and z coord, saved in list, made from Lands.cs as tile as Vector2