public BackToBackCount backToBackCountOnIndex(Vector2Int index, GemColor gemColor) { BackToBackCount count = new BackToBackCount(); Gem rootGem = gemsTable[index.x, index.y]; if (rootGem != null) { count.horizontalGems.Add(rootGem); count.verticalGems.Add(rootGem); } // Count left for (int x = index.x - 1; x >= 0; x--) { Gem gem = gemsTable[x, index.y]; if (gem == null || !gem.CanBeMatchedWith(gemColor)) { break; } else { count.horizontalGems.Add(gem); } } // Count right for (int x = index.x + 1; x < boardNumCells.x; x++) { Gem gem = gemsTable[x, index.y]; if (gem == null || !gem.CanBeMatchedWith(gemColor)) { break; } else { count.horizontalGems.Add(gem); } } // Count up for (int y = index.y + 1; y < boardNumCells.y; y++) { Gem gem = gemsTable[index.x, y]; if (gem == null || !gem.CanBeMatchedWith(gemColor)) { break; } else { count.verticalGems.Add(gem); } } // Count down for (int y = index.y - 1; y >= 0; y--) { Gem gem = gemsTable[index.x, y]; if (gem == null || !gem.CanBeMatchedWith(gemColor)) { break; } else { count.verticalGems.Add(gem); } } return(count); }