어제 다 완성하지 못한 캐릭터 Sprite 소스를 만들고, Wave System을 구현했다.
Monster 쪽은 Player의 컴포넌트들이 완성되어야 작업할 수 있을 것 같아서 일단 컴포넌트 스크립트만 만들고 주석처리 한 뒤 미뤄둠 히히
public void SetSpawnPositionInfo(float x, float y, float limit)
{
_centerPos.x = x;
_centerPos.y = y;
_limit = limit;
}
private void InitSpawnPositions()
{
for (int i = -1; i <= 1; i += 2)
{
for (int j = -1; j <= 1; j++)
{
float x = _centerPos.x + (j * _limit * 0.8f);
float y = _centerPos.y + (i * _limit * 0.8f);
_spawnPositions.Add(new Vector3(x, y));
}
}
}
// 웨이브 실행 코루틴 함수
IEnumerator COPlayWave()
{
while (_currentWaveIndex <= 10)
{
if (_currentSpawnCount == 0)
{
// 몬스터가 생성되는 포지션 수 증가
if (_currentWaveIndex % 5 == 0)
{
_waveSpawnPosCount = _waveSpawnPosCount + 1 > _spawnPositions.Count ? _waveSpawnPosCount : _waveSpawnPosCount + 1;
_waveSpawnCount = 0;
}
// 한 번에 만들어지는 몬스터 수 증가
if (_currentWaveIndex % 2 == 0)
{
_waveSpawnCount++;
}
for (int i = 0; i < _waveSpawnPosCount; i++)
{
int posIdx = Random.Range(0, _spawnPositions.Count);
for (int j = 0; j < _waveSpawnCount; j++)
{
int prefabIndex = Random.Range(0, _enemyPrefabs.Count);
GameObject enemy = Instantiate(_enemyPrefabs[prefabIndex], _spawnPositions[posIdx], Quaternion.identity);
// TODO Monster 스탯 변경
// TODO Monster Death 처리 함수 Event에 연결
_currentSpawnCount++;
yield return new WaitForSeconds(_spawnInterval);
}
}
_currentWaveIndex++;
}
yield return null;
}
}
// wave 프리팹의 경로
const string WAVE_PREFAB_PATH = "Prefabs/Waves/Wave";
private string _dataPath; // 현재 스테이지 정보를 받아와서 완성하는 최종 프리팹 경로
private int _curStage; // 현재 스테이지
private GameObject _wavePrefab;
private void Start()
{
_dataPath = WAVE_PREFAB_PATH + _curStage;
_wavePrefab = Resources.Load<GameObject>(_dataPath);
}
public void StartWave(bool isBossRoom, float x, float y, float limit)
{
...
_wavePrefab.GetComponent<Wave>().SetSpawnPositionInfo(x, y, limit);
Instantiate(_wavePrefab);
}
다시 에셋 노동하러 가볼까~,,
끗