(Unity6)Ballをジャンプさせる(インプットシステム)

(サンプルコード)

using UnityEngine;

public class Ball : MonoBehaviour
{
    private InputSystem_Actions isa;
    public float moveSpeed;
    private Rigidbody rb;

    // ★ジャンプ
    public float jumpPower;

    void Start()
    {
        isa = new InputSystem_Actions();
        isa.Enable();

        rb = GetComponent<Rigidbody>();
    }

    void Update()
    {
        Vector2 movement2 = isa.Player.Move.ReadValue();
        Vector3 movement3 = new Vector3(movement2.x, 0, movement2.y);
        rb.AddForce(movement3 * moveSpeed);

        // ★ジャンプ
        if(isa.Player.Jump.triggered)
        {
            rb.linearVelocity += Vector3.up * jumpPower;
        }
    }
}

(設定)

・Jump Powerの設定(自由)


(実行確認)

・スペースキーを押すとジャンプすれば成功