(Unity6 BRP)一定間隔でオブジェクトを生成する方法(コルーチンの活用)

(サンプルコード)

using UnityEngine;
// ★追加
using System.Collections;

public class AutoGene4 : MonoBehaviour
{
    public GameObject ballPrefab;

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

    private IEnumerator BallGene()
    {
        yield return new WaitForSeconds(1.0f);

        while(true)
        {
            Instantiate(ballPrefab, transform.position, Quaternion.identity);

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

(実行結果)