Contents
접기
728x90
오늘은 적이 등장할 때 멋진 이펙트(폭발, 소환 등) 가 먼저 나오고, 그 뒤에 적이 생성되도록 만드는 간단한 시스템을 구현했다.
목표
- 적 등장 전에 이펙트 프리팹을 먼저 보여주고
- 적을 그 자리에서 자연스럽게 생성
- 코루틴 없이 간단한 구조로 처리
구조 설명
이전에 만들어 두었던 EnemySpawnManager에서 적 스폰 코드 전 이펙트 실행 함수를 추가하였다.
EnemySpawnManager의 구조:
기능 | 설명 |
SpawnFromParent() | 부모 오브젝트 아래에 있는 스폰 포인트들을 찾아 적을 생성 |
PlaySpawnEffect() | 이펙트를 먼저 생성한 뒤 자동 제거 (0.5초 후) |
코드
using System;
using System.Collections.Generic;
using UnityEngine;
public class EnemySpawnManager : MonoBehaviour
{
[SerializeField] private GameObject _spawnEffectPrefab;
public List<GameObject> SpawnFromParent(Transform parent, Transform container = null, Action onCompleted = null)
{
List<GameObject> spawned = new List<GameObject>();
if (parent == null)
return spawned;
EnemySpawnPoint[] points = parent.GetComponentsInChildren<EnemySpawnPoint>();
foreach (var point in points)
{
if (point.enemyPrefabs == null || point.enemyPrefabs.Count == 0) continue;
foreach (var prefab in point.enemyPrefabs)
{
if (prefab == null) continue;
Vector3 spawnPos = point.transform.position;
PlaySpawnEffect(spawnPos);
GameObject enemy = Instantiate(prefab, spawnPos, Quaternion.identity, container);
spawned.Add(enemy);
}
}
onCompleted?.Invoke();
return spawned;
}
private void PlaySpawnEffect(Vector3 position)
{
if (_spawnEffectPrefab == null) return;
GameObject fx = Instantiate(_spawnEffectPrefab, position, Quaternion.identity);
Destroy(fx, 0.5f);
}
}
사용법
- EnemySpawnPoint에는 적 프리팹들을 리스트로 넣어준다.
- SpawnEffectPrefab에는 폭발, 소환 같은 이펙트 프리팹을 넣는다.
- SpawnFromParent()를 호출하면 자동으로:
- 이펙트가 생성되고
- 그 다음 적이 생성된다.
728x90
'GameDevelop > Unity팀프로젝트' 카테고리의 다른 글
유니티 말풍선 따라다니기 구현 (TextAnimator + SpeechBubble) (1) | 2025.07.31 |
---|---|
Unity | 플레이어 위치에 따라 따라오는 '핀치새' 구현하기 (1) | 2025.07.30 |
유니티 스폰 애니메이션 (2) | 2025.07.28 |
Unity 2D 게임에서 패럴랙스 배경 만들기 + 무한 반복 연결 (3) | 2025.07.25 |
Unity 컷신에 애니메이션 넣기 (Dialogue System 연동) (0) | 2025.07.24 |