(Unity6 BRP)連射モードの実装(インプットシステム)

(サンプルコード)

using UnityEngine;

public class Fire : MonoBehaviour
{
    // ★インプットシステム
    private InputSystem_Actions isa;

    public GameObject beamPrefab;
    private int count;
    public AudioClip sound;

    private void Start()
    {
        // ★インプットシステム
        isa = new InputSystem_Actions();
        isa.Enable();
    }

    private void FixedUpdate()
    {
        // ★インプットシステム
        if (isa.Player.Attack.IsPressed()) // エンターキーを押している時(ポイント)
        {
            count += 1;

            if (count % 5 == 0)
            {
                Instantiate(beamPrefab, transform.position, Quaternion.identity);
                AudioSource.PlayClipAtPoint(sound, transform.position);
            }
        }
    }

    // ★インプットシステム
    private void OnDisable()
    {
        isa.Disable();
    }
}

(実行結果)

・エンターキーを押している間、連射できれば成功