상세 컨텐츠

본문 제목

유니티 그리드 적 소환하기

유니티/기능

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

 

 

 

 

 

 

 

 

 

관련글 더보기