Exemplo n.º 1
0
    public bool Push(Vector3 movementVector)
    {
        bool       allowedToMove = true;
        bool       moveSuccess   = false;
        GameObject objectPushed  = getAdjacent(movementVector);

        if (objectPushed != null)
        {
            allowedToMove = PromptPush(objectPushed, movementVector);
        }

        if (allowedToMove)
        {
            GameObject objectCarried = getAdjacent(Vector3.up);
            if (objectCarried != null)
            {
                PromptPush(objectCarried, movementVector);
            }

            moveSuccess = grid.MoveObject(
                gameObject,
                (int)(transform.position.x + movementVector.x),
                (int)(transform.position.y + movementVector.y),
                (int)(transform.position.z + movementVector.z)
                );

            if (moveSuccess)
            {
                transform.Translate(movementVector);
            }
        }

        return(allowedToMove && moveSuccess);
    }