★Shotaro_Ohashi

(2026年2月2日)

<砲塔と砲弾の角度を合致させる>

・「ShotShell」スクリプトの改良

using UnityEngine;
using TMPro;
public class ShotShell : MonoBehaviour
{
    public GameObject muzzlePrefab;
    public GameObject muzzlePoint;
    private InputSystem_Actions isa;
    public GameObject shellPrefab;
    public GameObject shell2Prefab;
    public AudioClip shotSound;
    public AudioClip shot2Sound;
    public float shotSpeed;
    public GameObject shotPoint;
    private float shotPower;
    private int count;
    public int shellCount;
    public int shell2Count;
    public TextMeshProUGUI shellLabel;
    public TextMeshProUGUI shell2Label;
    public TextMeshProUGUI FPSshellLabel;
    public TextMeshProUGUI FPSshell2Label;
    private int maxShell = 50;
    public AudioClip itemSound;
    void Start()
    {
        isa = new InputSystem_Actions();
        isa.Enable();
        shellLabel.text = "" + shellCount;
        shell2Label.text = "" + shell2Count;
        FPSshellLabel.text = "" + shellCount;
        FPSshell2Label.text = "" + shell2Count;
    }
    void Update()
    {
        if (isa.Player.Shot2.IsInProgress() && shell2Count > 0)
        {
            shell2Count -= 1;
            shell2Label.text = "" + shell2Count;
            FPSshell2Label.text = "" + shell2Count;
            count += 1;
            if (count % 120 == 0)
            {
                //GameObject muzzle = Instantiate(muzzlePrefab, muzzlePoint.transform.position, Quaternion.Euler(shotPoint.transform.eulerAngles.x, transform.eulerAngles.y - 90, 0));
                // ★修正(2月2日)
                GameObject shell = Instantiate(shell2Prefab, shotPoint.transform.position, Quaternion.Euler(shotPoint.transform.eulerAngles.x + 90, transform.root.eulerAngles.y, 0));
                Rigidbody shellRd = shell.GetComponent();
                // ★修正(2月2日)
                shellRd.AddForce(shotPoint.transform.forward * shotSpeed);
                Destroy(shell, 2.0f);
                AudioSource.PlayClipAtPoint(shot2Sound, transform.position);
            }
        }
        if (isa.Player.Shot2.IsPressed())
        {
            shotPower += 15f;
            if (shotPower > 900f)
            {
                shotPower = 900f;
            }
        }
        if (isa.Player.Shot.WasReleasedThisFrame() && shellCount > 0)
        {
            shellCount -= 1;
            shellLabel.text = "" + shellCount;
            FPSshellLabel.text = "" + shellCount;
            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 * shotPower);
            AudioSource.PlayClipAtPoint(shotSound, Camera.main.transform.position);
            Destroy(shell, 5.0f);
            shotPower = 10000;
        }
    }
    private void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("ShellItem"))
        {
            Destroy(other.gameObject);
            AudioSource.PlayClipAtPoint(itemSound, transform.position);
            shellCount += 25;
            shellLabel.text = "" + shellCount;
            FPSshellLabel.text = "" + shellCount;
        }
    }
    private void OnDisable()
    {
        isa.Disable();
    }
}

(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();
    }
}

(設定)