Exemplo n.º 1
0
    private void UpgradeTile(GameObject toDestroy, Tile destroyTile, GameObject toUpgrade, Tile upgradeTile)
    {
        Vector3 toDestroyPosition = toDestroy.transform.position;
        Vector3 toUpgradePosition = toUpgrade.transform.position;
        Vector2 upgradeGridPoint  = WorldToGridPoint(toUpgradePosition.x, toUpgradePosition.y);
        Vector2 destroyGridPoint  = WorldToGridPoint(toDestroyPosition.x, toDestroyPosition.y);

        // create the upgraded tile
        GameObject newTile = (GameObject)Instantiate(tilePrefabs[upgradeTile.power], toUpgradePosition, transform.rotation);

        // set the upgrade tile's grid value to double its current value
        grid[Mathf.RoundToInt(upgradeGridPoint.x), Mathf.RoundToInt(upgradeGridPoint.y)] = upgradeTile.value * 2;

        // clear out the destroyed tile's grid entry
        grid[Mathf.RoundToInt(destroyGridPoint.x), Mathf.RoundToInt(destroyGridPoint.y)] = 0;

        points        += upgradeTile.value * 2;
        scoreText.text = points.ToString();

        // destroy both tiles
        Destroy(toDestroy);
        Destroy(toUpgrade);
        currentTilesAmount--;
        TileAnimationHandler tileAnim = newTile.GetComponent <TileAnimationHandler>();

        tileAnim.AnimateUpgrade();
    }
Exemplo n.º 2
0
    private void UpgradeTile(GameObject toDestroy, Tile destroyTile, GameObject toUpgrade, Tile upgradeTile)
    {
        Vector3 toUpgradePosition = toUpgrade.transform.position;

        tiles.Remove(toDestroy);
        tiles.Remove(toUpgrade);

        SimplePool.Despawn(toDestroy);
        SimplePool.Despawn(toUpgrade);

        // create the upgraded tile
        GameObject newTile = SimplePool.Spawn(tilePrefabs[upgradeTile.power], toUpgradePosition, transform.rotation);

        tiles.Add(newTile);
        Tile tile = newTile.GetComponent <Tile>();

        tile.upgradedThisTurn = true;

        points        += upgradeTile.value * 2;
        scoreText.text = points.ToString();

        TileAnimationHandler tileAnim = newTile.GetComponent <TileAnimationHandler>();

        tileAnim.AnimateUpgrade();
    }