예제 #1
0
    void AttemptToMove(Vector3 direction)
    {
        RaycastHit2D hit = Physics2D.Raycast(transform.position, direction, 1);

        if (hit.collider == null)
        {
            lerpMovement.MoveBy(direction);
        }
        else if (hit.collider.tag == "Movable")
        {
            var movableObject = hit.transform.GetComponent <MovableObject>();
            if (movableObject != null)
            {
                if (movableObject.AttemptPush(direction))
                {
                    lerpMovement.MoveBy(direction);
                }
            }
        }
    }
예제 #2
0
    public bool AttemptPush(Vector3 direction)
    {
        if (!lerpMovement.isMoving)
        {
            RaycastHit2D hit = Physics2D.Raycast(transform.position, direction, 1);
            if (hit.collider == null)
            {
                lerpMovement.MoveBy(direction);

                if (currentGoal != null)
                {
                    if (OnUnsatisfyGoal != null)
                    {
                        OnUnsatisfyGoal(currentGoal);
                    }
                }

                return(true);
            }
        }
        return(false);
    }