2022-11-28 22:54:08 +00:00
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
public class EnemyContainer : MonoBehaviour
|
|
|
|
{
|
|
|
|
public GameObject enemyPrefab;
|
2023-06-30 09:30:12 +00:00
|
|
|
public GameObject environmentObj;
|
|
|
|
public GameObject targetControllerObj;
|
2022-11-28 22:54:08 +00:00
|
|
|
|
|
|
|
private TargetController targetCon;
|
|
|
|
|
|
|
|
private void Start()
|
|
|
|
{
|
2023-06-30 09:30:12 +00:00
|
|
|
targetCon = targetControllerObj.GetComponent<TargetController>();
|
2022-11-28 22:54:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// initialize enemy by random
|
2023-06-30 09:30:12 +00:00
|
|
|
public void RandomInitEnemys(int EnemyNum)
|
2022-11-28 22:54:08 +00:00
|
|
|
{
|
2023-07-28 19:04:18 +00:00
|
|
|
Debug.Log("RandomInitEnemys");
|
2022-11-28 22:54:08 +00:00
|
|
|
for (int i = 0; i < EnemyNum; i++)
|
|
|
|
{
|
|
|
|
float randX = UnityEngine.Random.Range(targetCon.minEnemyAreaX, targetCon.maxEnemyAreaX);
|
|
|
|
float randZ = UnityEngine.Random.Range(targetCon.minEnemyAreaZ, targetCon.maxEnemyAreaZ);
|
|
|
|
int enemyY = 1;
|
2023-06-30 09:30:12 +00:00
|
|
|
InitEnemyAtHere(new Vector3(randX, enemyY, randZ));
|
2022-11-28 22:54:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// initialize enemy by random but not in block area
|
2023-06-30 09:30:12 +00:00
|
|
|
public void RandomInitEnemysExcept(int enemyNum, Vector3 blockPosition, float sceneSize)
|
2022-11-28 22:54:08 +00:00
|
|
|
{
|
|
|
|
float randX = 0f;
|
|
|
|
float randZ = 0f;
|
|
|
|
for (int i = 0; i < enemyNum; i++)
|
|
|
|
{
|
|
|
|
randX = UnityEngine.Random.Range(targetCon.minEnemyAreaX, targetCon.maxEnemyAreaX);
|
|
|
|
randZ = UnityEngine.Random.Range(targetCon.minEnemyAreaZ, targetCon.maxEnemyAreaZ);
|
2023-06-30 09:30:12 +00:00
|
|
|
while (Vector3.Distance(blockPosition, new Vector3(randX, 0f, randZ)) < sceneSize / 2)
|
2022-11-28 22:54:08 +00:00
|
|
|
{
|
|
|
|
// while in scene area then respawn
|
|
|
|
Debug.Log("spawn enemy in area, re:roll");
|
|
|
|
randX = UnityEngine.Random.Range(targetCon.minEnemyAreaX, targetCon.maxEnemyAreaX);
|
|
|
|
randZ = UnityEngine.Random.Range(targetCon.minEnemyAreaZ, targetCon.maxEnemyAreaZ);
|
|
|
|
}
|
|
|
|
|
|
|
|
int enemyY = 1;
|
2023-06-30 09:30:12 +00:00
|
|
|
InitEnemyAtHere(new Vector3(randX, enemyY, randZ));
|
2022-11-28 22:54:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-22 17:58:50 +00:00
|
|
|
// initialize enemy to position
|
|
|
|
public void InitEnemyAtHere(Vector3 position)
|
2022-11-28 22:54:08 +00:00
|
|
|
{
|
2023-08-22 17:58:50 +00:00
|
|
|
Instantiate(enemyPrefab, position + environmentObj.transform.position, Quaternion.identity, this.transform);
|
2022-11-28 22:54:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// destroyEnemy delete enemyContainer's all enemy
|
2023-06-30 09:30:12 +00:00
|
|
|
public void DestroyAllEnemys()
|
2022-11-28 22:54:08 +00:00
|
|
|
{
|
|
|
|
foreach (Transform childObj in this.transform)
|
|
|
|
{
|
2023-06-30 09:30:12 +00:00
|
|
|
childObj.GetComponent<States>().DestroyMe();
|
2022-11-28 22:54:08 +00:00
|
|
|
}
|
|
|
|
}
|
2023-06-30 09:30:12 +00:00
|
|
|
}
|