Pools | 유틸리티 도구 | Unity Asset Store
Use the Pools from Redcode Games on your next project. Find this utility tool & more on the Unity Asset Store.
assetstore.unity.com
using Redcode.Pools;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.Tracing;
using UnityEngine;
public class EnemyGenerator2 : MonoBehaviour
{
[SerializeField]
private PoolManager poolManager;
private void Start()
{
// PoolManager 인스턴스를 찾습니다.
PoolManager poolManager = FindObjectOfType<PoolManager>();
// 코루틴 시작
StartCoroutine(CreateEnemy());
}
IEnumerator CreateEnemy()
{
for (int i = 0; i < 10; i++)
{
EnemyController enemy = poolManager.GetFromPool<EnemyController>(0);
// 여기서 0은 풀의 인덱스입니다.
Debug.LogFormat("enemy {0}", enemy);
// 가져온 오브젝트를 사용합니다.
if (enemy != null)
{
enemy.gameObject.SetActive(true);
// 오브젝트가 성공적으로 가져와졌다면, 여기서 추가 작업을 수행합니다.
enemy.transform.position = new Vector3(Random.Range(-2f, 2f), 6f, 0); // 예를 들어, 오브젝트의 위치를 월드의 중앙으로 설정합니다.
}
yield return new WaitForSeconds(2f);
}
}
}
'게임프로젝트 > 슈팅게임' 카테고리의 다른 글
팀프로젝트 (2) 플레이어 조이스틱 이동 (0) | 2024.03.21 |
---|---|
팀프로젝트 (1) App , Game Main스크립트 작성 (0) | 2024.03.21 |
ShootingSpace (5) 아이템 획득, 붐 이펙트 (0) | 2024.03.19 |
ShootingSpace (4) UI만들기 (0) | 2024.03.16 |
ShootingSpace (3) 플레이어와 적, 적 총알과 충돌 (0) | 2024.03.12 |