public void CallRandomEnemy(int _stageNum) { enemyInfoList.Clear(); List <GameObject> curStageEnemy = new List <GameObject>(); int enemyCount = Random.Range(4, 10); for (int i = 0; i <= enemyCount; i++) { int randomNum = Random.Range(0, 2); curStageEnemy.Add(enemyFactory.CallEnemy((ENEMYTYPE)randomNum)); } if (_stageNum >= 4) { int randomNum = Random.Range(0, 2); if (randomNum == 1) { curStageEnemy.Add(enemyFactory.CallEnemy(ENEMYTYPE.ELEPHANTSLUG)); } } stageEnemys.Add(curStageEnemy); //층별로 적 게임오브젝트 저장 //적 목록을 뽑아 저장 for (int i = 0; i < curStageEnemy.Count; i++) { enemyInfoList.Add(curStageEnemy[i].GetComponent <Enemy>()); } }
public void CallRandomEnemy(int _stageNum) { PoolOff(); enemyInfoList.Clear(); int enemyCount = Random.Range(4, 10); Debug.Log("현재 층 생성된 몬스터 수 : " + enemyCount); for (int i = 0; i < enemyCount; i++) { Position spawnPos = enemyFactory.FindValidateTile(); int randomNum = 0; bool isSet = false; if (_stageNum < 4) { randomNum = Random.Range(0, 2); } else if (_stageNum >= 4) { randomNum = Random.Range(0, 3); } switch ((ENEMYTYPE)randomNum) { case ENEMYTYPE.JELLY: for (int j = 0; j < JellyPool.Count; j++) { if (JellyPool[j].activeSelf) { continue; } JellyPool[j].SetActive(true); JellyPool[j].transform.position = new Vector2(spawnPos.PosX, spawnPos.PosY); JellyPool[j].GetComponent <Corrosive_Jelly>().EnemyInit(); JellyPool[j].GetComponent <Corrosive_Jelly>().Init(); isSet = true; break; } if (isSet == false) { JellyPool.Add(enemyFactory.CallEnemy(ENEMYTYPE.JELLY)); } break; case ENEMYTYPE.RAT: for (int j = 0; j < RatPool.Count; j++) { if (RatPool[j].activeSelf) { continue; } RatPool[j].SetActive(true); RatPool[j].transform.position = new Vector2(spawnPos.PosX, spawnPos.PosY); RatPool[j].GetComponent <Rat>().EnemyInit(); RatPool[j].GetComponent <Rat>().Init(); isSet = true; break; } if (isSet == false) { RatPool.Add(enemyFactory.CallEnemy(ENEMYTYPE.RAT)); } break; case ENEMYTYPE.ELEPHANTSLUG: for (int j = 0; j < SlugPool.Count; j++) { if (SlugPool[j].activeSelf) { continue; } SlugPool[j].SetActive(true); SlugPool[j].transform.position = new Vector2(spawnPos.PosX, spawnPos.PosY); SlugPool[j].GetComponent <Elephant_Slug>().EnemyInit(); SlugPool[j].GetComponent <Elephant_Slug>().Init(); isSet = true; break; } if (isSet == false) { SlugPool.Add(enemyFactory.CallEnemy(ENEMYTYPE.ELEPHANTSLUG)); } break; } } for (int i = 0; i < JellyPool.Count; i++) { if (JellyPool[i].activeSelf) { enemyInfoList.Add(JellyPool[i].GetComponent <Corrosive_Jelly>()); } } for (int i = 0; i < RatPool.Count; i++) { if (RatPool[i].activeSelf) { enemyInfoList.Add(RatPool[i].GetComponent <Rat>()); } } for (int i = 0; i < SlugPool.Count; i++) { if (SlugPool[i].activeSelf) { enemyInfoList.Add(SlugPool[i].GetComponent <Elephant_Slug>()); } } List <EnemyData> curStageEnemy = new List <EnemyData>(); for (int i = 0; i < enemyInfoList.Count; i++) { curStageEnemy.Add(enemyInfoList[i].enemyData); } stageEnemys.Add(curStageEnemy); }