유니티/기능
유니티 그리드 적 소환하기
MJ_119
2024. 9. 5. 00:21
가장 기초.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ObjectPool : MonoBehaviour
{
[SerializeField] GameObject enemyPrefabs;
void Start()
{
// 게임 시작 시 코루틴 시작
StartCoroutine(SpawnEnemy());
}
IEnumerator SpawnEnemy()
{
while (true) // 무한 반복을 통해 1초마다 적 생성
{
Instantiate(enemyPrefabs, transform.position, Quaternion.identity);
yield return new WaitForSeconds(1);
}
}
}