/// <summary> /// Get the cell at given position in the world. /// </summary> /// <param name="positionHit">Position where raycast hit the cell.</param> /// <returns>Cell being hit.</returns> public HexCell GetCell(Vector3 positionHit) { // Transform hit position from world space to local space positionHit = transform.InverseTransformPoint(positionHit); // Obtain the coordinates of the cell being hit HexCoordinates cellHitCoordinates = HexCoordinates.FromPositionHitToCellCoordinates(positionHit); int hitCellIndex = cellHitCoordinates.X + cellHitCoordinates.Z * width + cellHitCoordinates.Z / 2; return(_cells[hitCellIndex]); }