コード例 #1
0
    private void OnButtonWest()
    {
        //Attack/Grab/Release
        if (!hasToy && grabRadius.CanReachToy())
        {
            Collider2D toy = grabRadius.getToy();
            hasToy = true;
            BallInMouth ballInMouth = GetComponentInChildren <BallInMouth>();
            ballInMouth.EnableBallInMouth();
            Destroy(toy.gameObject);
        }
        else if (hasToy)
        {
            Vector3 ballEjectPos = transform.position;
            ballEjectPos.y += .2f;
            Rigidbody2D ballRB = Instantiate(ballPrefab, ballEjectPos, transform.rotation);

            if (isFacingRight)
            {
                ballRB.velocity = new Vector2(dropItemSpeed, dropItemSpeed);
            }
            else
            {
                ballRB.velocity = new Vector2(-dropItemSpeed, dropItemSpeed);
            }
            hasToy = false;
            BallInMouth ballInMouth = GetComponentInChildren <BallInMouth>();
            ballInMouth.DisableBallInMouth();
        }
        else
        {
            //attack
            if (isSlashing != true)
            {
                slash.SetActive(true);
                Slash slashScript = slash.GetComponent <Slash>();
                slashScript.isFacingRight = isFacingRight;
                isSlashing = true;
                StartCoroutine("SlashAnimation");
            }
        }
    }
コード例 #2
0
    public void DropToy(bool directionRight)
    {
        if (hasToy)
        {
            Vector3 ballEjectPos = transform.position;
            ballEjectPos.y += .2f;
            Rigidbody2D ballRB = Instantiate(ballPrefab, ballEjectPos, transform.rotation);

            if (directionRight)
            {
                ballRB.velocity = new Vector2(dropItemSpeed, dropItemSpeed);
            }
            else
            {
                ballRB.velocity = new Vector2(-dropItemSpeed, dropItemSpeed);
            }
            hasToy = false;
            BallInMouth ballInMouth = GetComponentInChildren <BallInMouth>();
            ballInMouth.DisableBallInMouth();
        }
    }