1

私はUnityを初めて使用し、2Dでキャラクターのドロップ攻撃を作成しようとしてZいます。キャラクターがジャンプしているときに攻撃ボタンを押すと、ドロップ攻撃のように斜めの線として急降下します。私のコードは以下のとおりです。

private Rigidbody2D rb;
private Animator anm;
private Collider2D coll;

private void Movement()
{
    float hDir = Input.GetAxis("Horizontal");
    if(!anm.GetCurrentAnimatorStateInfo(0).IsTag("attack"))
    {
        if (hDir < 0)
        {
            rb.velocity = new Vector2(-speedX, rb.velocity.y);
            transform.localScale = new Vector2(-1, 1);
        }
        else if (hDir > 0)
        {
            rb.velocity = new Vector2(speedX, rb.velocity.y);
            transform.localScale = new Vector2(1, 1);
        }
    }
    else if(anm.GetCurrentAnimatorStateInfo(0).IsTag("attack"))
    {
        rb.velocity = new Vector2(0, 0);
    }

    if (Input.GetButtonDown("Jump") && coll.IsTouchingLayers(ground))
    {
        Jump();
    }
}

private void Attack() {
    anm.SetTrigger("attack");
    if (!coll.IsTouchingLayers(ground)) {
        rb.velocity = new Vector2(speedX * Time.deltaTime, rb.velocity.y);
    }
}

private void Jump() {
    rb.velocity = new Vector2(rb.velocity.x, jumpforce);
    state = State.jumping;
}

私はそれが機能で何かをしていると思いAttack()ます。

4

0 に答える 0