コード例 #1
0
    void handlePickUp()
    {
        if (MyInput.GetPickUp() && !isPickingUp)
        {
            isPickingUp = true;
            if (!hasBox)
            {
                Collider2D boxsCollider = Physics2D.OverlapCircle(rightWallCheck.position, groundRadius, whatIsBoxes);
                if (boxsCollider != null)
                {
                    setBox(boxsCollider.transform);
                }
            }
            else
            {
                RaycastHit2D hit2D = Physics2D.Raycast(this.transform.position, this.transform.localScale.x * Vector2.right, 10f, 1 << LayerMask.NameToLayer("Floor"));

                box.SetActive(true);
                box.transform.SetParent(null);
                box.transform.position = this.transform.position + new Vector3(facingRight ? 12.5f : -12f, 6.5f, -28);
                if (hit2D.collider != null && hit2D.distance < 10f)
                {
                    print("worked");
                    box.transform.Translate((-1 * this.transform.localScale.x) * (this.transform.right * 10f));
                }
                box    = null;
                hasBox = false;
                anim.SetTrigger("lostBox");
            }
        }
        else if (isPickingUp && !MyInput.GetPickUp())
        {
            isPickingUp = false;
        }
        anim.SetBool("hasBox", hasBox);
    }