0

I currently have a row a column saved by using the following two lines of code:

private List<Tile[]> columns = new List<Tile[]>();
private List<Tile[]> rows = new List<Tile[]>();

Is there a way to create a variable that can take the column and index so that I can get the location of where the user clicked? Something like this:

indexOfClick = [row, column]; 

EDIT: How I'm adding a column and row:

columns.Add(new Tile[]{AllTiles[0, 0], AllTiles[1, 0], AllTiles[2, 0], AllTiles[3, 0] });

rows.Add(new Tile[]{AllTiles[0, 0], AllTiles[0, 1], AllTiles[0, 2], AllTiles[0, 3] });
sam1319
  • 201
  • 1
  • 6
  • 16

3 Answers3

2

You can use tuples for this :

var indexOfClick = (row, column);
Selmir
  • 1,136
  • 1
  • 11
  • 21
  • I tried a tuple but it gives me an error because the version of C# that I'm using with Unity doesn't support tuples. – sam1319 Aug 25 '18 at 19:45
1

You may create a custom Struct or Class:

public class Cell
{
    public int Row { get; }
    public int Column { get; }

    public Cell(int row, int column)
    {
        Row = row;
        Column = column;
    }
}

Alternatively, you may use Tuple Class or ValueTuple Struct.

FlashOver
  • 1,855
  • 1
  • 13
  • 24
0

You can use Unity's built in integer-vector struct:

    List<Vector2Int> Coords;

and thus

    Coords.Add( new Vector2Int( clickX, clickY ) );
Immersive
  • 1,684
  • 1
  • 11
  • 9