public void ColorCell(Vector3 position, Color color) { position = transform.InverseTransformPoint(position); HexCoords coords = HexCoords.FromPosition(position); // Gets the index of the cell // (I don't know why this works) int index = coords.X + coords.Z * width + coords.Z / 2; // Checks that index is in the range of the array if (index >= cells.Length || index < 0) { return; } // get the cell using index HexCell cell = cells[index]; cell.color = color; hexMesh.Triangulate(cells); }