public void Swap(Sc_Tile firstTile, Sc_Tile secondTile) { canSwap = false; Sc_EventManager.instance.onUpdateStats.Invoke(); gameManager.ChangeAction(-1); Vector2Int objCoord = GetTileCoordinates(firstTile.gameObject); Vector2Int toSwapCoord = GetTileCoordinates(secondTile.gameObject); Vector2 objPosition = firstTile.transform.position; Vector2 swapPosition = secondTile.transform.position; grid[objCoord.x, objCoord.y] = secondTile.gameObject; firstTile.coordinates = toSwapCoord; grid[toSwapCoord.x, toSwapCoord.y] = firstTile.gameObject; secondTile.coordinates = objCoord; secondTile.transform.DOMove(objPosition, swapDuration); firstTile.transform.DOMove(swapPosition, swapDuration); secondTile.gameObject.name = secondTile.ToString(); firstTile.gameObject.name = firstTile.ToString(); StartCoroutine(CheckThisTile(firstTile, swapDuration)); StartCoroutine(CheckThisTile(secondTile, swapDuration)); }
public GameObject CreateTile(int j, int i) { int random = Random.Range(0, allTiles.Length); GameObject newTile = Instantiate(allTiles[random], transform.position + new Vector3(j, -i, 0), Quaternion.identity, transform); Sc_Tile tile = newTile.GetComponent <Sc_Tile>(); tile.coordinates = new Vector2Int(j, i); tile.name = tile.ToString(); return(newTile); }