敵の攻撃(コルーチン)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyShotShell : MonoBehaviour
{
    public GameObject enemyShellPrefab;
    public float shotSpeed;
    public AudioClip shotSound;

    void Start()
    {
        StartCoroutine(Shot());
    }

    // コルーチン
    private IEnumerator Shot()
    {
        while(true)
        {
            GameObject enemyShell = Instantiate(enemyShellPrefab, transform.position, Quaternion.identity);
            Rigidbody enemyShellRb = enemyShell.GetComponent<Rigidbody>();
            enemyShellRb.AddForce(transform.forward * shotSpeed);
            Destroy(enemyShell, 1.5f);
            AudioSource.PlayClipAtPoint(shotSound, transform.position);

            yield return new WaitForSeconds(1f);
        }
    }
}