示例#1
0
    public bool MoveCharToObject(GameObject obj, SpringAction action = null, IInteractable interactable = null)
    {
        if (!CanCharacterMove)
        {
            if (action != null)
            {
                StateManager.Instance.DispatchAction(action, interactable);
                if (interactable != null && interactable.orientation != Orientation.UNSPECIFIED)
                {
                    GameObject.FindGameObjectWithTag("Character")
                    .GetComponent <SkeletonAnimation>()
                    .skeleton.FlipX = interactable.orientation == Orientation.LEFT;
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }

        RaycastHit2D hit = Physics2D.Raycast(obj.transform.position, -Vector2.up, Mathf.Infinity, 0 | (1 << LayerMask.NameToLayer("WalkableArea")));
        Vector2      destination;

        //Debug.Log(hit.point);
        if (hit.collider == null)
        {
            hit = Physics2D.Raycast(obj.transform.position, Vector2.up, Mathf.Infinity, 0 | (1 << LayerMask.NameToLayer("WalkableArea")));
            //Debug.Log(hit.point);
            destination    = hit.point;
            destination.y += 0.001f;
        }
        else
        {
            destination    = hit.point;
            destination.y -= 0.001f;
        }
        if (hit.collider != null)
        {
            //Debug.Log(hit.collider.name);
            CharacterInput walkableArea = hit.collider.gameObject.GetComponent <CharacterInput>();
            if (walkableArea != null)
            {
                walkableArea.MoveToPoint(destination, action, interactable);
                return(true);
            }
        }

        return(false);
    }