★Shotaro_Ohashi

(2025年12月6日)

<マズルフラッシュ>

using UnityEngine;

public class ShotShell : MonoBehaviour
{
    // ★追加(マズルフラッシュ)
    public GameObject muzzlePrefab;
    public GameObject muzzlePoint;

    private InputSystem_Actions isa;
    public GameObject shellPrefab;
    public AudioClip shotSound;
    public float shotSpeed;
    public GameObject shotPoint;
    private float shotPower;
    void Start()
    {
        isa = new InputSystem_Actions();
        isa.Enable();
    }
    void Update()
    {
        if (isa.Player.Shot.triggered)
        {
            // ★追加(マズルフラッシュ)
            GameObject muzzle = Instantiate(muzzlePrefab, muzzlePoint.transform.position, Quaternion.Euler(0, transform.eulerAngles.y - 90, 0));
            Destroy(muzzle, 0.15f);

            GameObject shell = Instantiate(shellPrefab, shotPoint.transform.position, Quaternion.Euler(90, transform.root.eulerAngles.y, 0));
            Rigidbody shellRd = shell.GetComponent();
            shellRd.AddForce(transform.forward * shotSpeed);
            Destroy(shell, 3.0f);
            AudioSource.PlayClipAtPoint(shotSound, transform.position);
        }
        if (isa.Player.Shot2.IsPressed())
        {
            shotPower += 15f;

            if (shotPower > 900f)
            {
                shotPower = 900f;
            }
        }
        if (isa.Player.Shot2.WasReleasedThisFrame())
        {
            // ★追加(マズルフラッシュ)
            GameObject muzzle = Instantiate(muzzlePrefab, muzzlePoint.transform.position, Quaternion.Euler(0, transform.eulerAngles.y - 90, 0));
            Destroy(muzzle, 0.15f);

            GameObject shell = Instantiate(shellPrefab, shotPoint.transform.position, Quaternion.Euler(90, transform.root.eulerAngles.y, 0));
            Rigidbody shellRd = shell.GetComponent();
            shellRd.useGravity = true;
            shellRd.AddForce((transform.forward + new Vector3(0, 0.5f, 0)) * shotPower);
            AudioSource.PlayClipAtPoint(shotSound, transform.position);
            Destroy(shell, 5.0f);
            shotPower = 0;
        }
    }
    private void OnDisable()
    {
        isa.Disable();
    }
}

(設定)