Spawn vật thể theo thời gian
C# Code
using UnityEngine;
public class ObjectSpawner : MonoBehaviour
{
public GameObject objectToSpawn;
public float spawnInterval = 2f;
private float timer;
void Update()
{
timer += Time.deltaTime;
if (timer >= spawnInterval)
{
Instantiate(objectToSpawn, transform.position, transform.rotation);
timer = 0f;
}
}
}Một script đơn giản để tạo (spawn) các vật thể (prefabs) theo một khoảng thời gian định trước.