title: grab grid tiles in unity
body: <p>First of all: I'm quite new to unity and c#, so please be nice if I ask dumb questions.</p>
  <p>I'm trying to make a game like minesweeper. So I want an easy grid with covered tiles and if you klick on one, it opens up.</p>
  <p>I use a main script I create a grid like so:</p>
  <pre><code>private void CreateTieleSet(int width, int height){
      _tiles = new Dictionary&lt;Vector2, Tile&gt;();
      for (int x = 0; x &lt; width; x++) 
      {
          for (int y = 0; y &lt; height; y++) 
          {
              var spawnedTile = Instantiate(_tilePrefab, new Vector3(x, y), Quaternion.identity);
              spawnedTile.name = $&quot;Tile {x} {y}&quot;;
              spawnedTile.status = field[x, y];
  
              _tiles[new Vector2(x, y)] = spawnedTile;
          }
      }
  }
  </code></pre>
  <p>I use the function</p>
  <pre><code>public Tile GetTileAtPosition(Vector2 pos)
  {
      if(_tiles.TryGetValue(pos, out var tile))
      {
          return tile;
      }
      return null;
  }
  </code></pre>
  <p>to get the tile at the position xy, but I can't use it since</p>
  <pre><code>Tile tempTile = GetTileAtPosition(new Vector2(x, y));
  tempTile.ChangeSprite(field[x, y]);    //example-funktion from tile-script
  </code></pre>
  <p>allways results in NullReferenceExeption-Error. I know the probleme, since I allways struggle with using scripts from other tiles. Bus usually I can use [SerializeField] Tile... and than dragdrop it onto it. In this case however I obvioulsy can't do that.</p>
  <p>Btw: I realy tried to solve this problem with other solutions found online, but everyone has complete different ideas how to do it and nothing seems to work for me :/</p>