Exemplo n.º 1
0
    void Update()
    {
        if (State == BlockState.BREAKING || State == BlockState.COLLECTING || State == BlockState.SWAPPING)
        {
            return;
        }

        if (MyTile != null && Fallable)
        {
            if (transform.position.y > MyTile.transform.position.y)
            {
                State = BlockState.FALLING;
            }

            // board object is settled squarely on its tile
            if (State == BlockState.SETTLED)
            {
                // if tile below becomes unoccupied, start falling again!
                Tile tileBelow = getTileAdjacent(0, 1);
                if (tileBelow != null && !tileBelow.IsOccupied(TileLayer))
                {
                    State = BlockState.FALLING;
                }
            }
            // the board object is falling vertically down
            else if (State == BlockState.FALLING)
            {
                // if the board object has fallen further than the targeted tile
                if (transform.position.y <= MyTile.transform.position.y)
                {
                    Tile targetTile = getTileAdjacent(0, 1);
                    if (targetTile == null || (targetTile != null && targetTile.IsOccupied(TileLayer)))
                    {
                        _velocity          = Vector3.zero;
                        transform.position = MyTile.transform.position;
                        State = BlockState.SETTLED;

                        if (!isBlockAbove())
                        {
                            if (!MyBoard.BreakMatchesInColumn(X))
                            {
                                MyBoard.ResetComboMultiplierForColumn(1, this);
                            }
                        }
                    }
                    // if not blocked then move to it
                    else if (targetTile != null)
                    {
                        MyTile.RemoveBoardObject(TileLayer);
                        targetTile.AddBoardObject(this, false);
                        advanceFallingObject();
                    }
                }
                else
                {
                    advanceFallingObject();
                }
            }
        }
    }