修复敌人生成的Bug
This commit is contained in:
parent
957565017a
commit
a11428678c
@ -27,6 +27,7 @@ public class ObJPool<T>
|
||||
{
|
||||
if (SurvivalPool.Contains(obj))
|
||||
{
|
||||
|
||||
SurvivalPool.Remove(obj);
|
||||
DeathPool.Add(obj);
|
||||
}
|
||||
@ -38,7 +39,7 @@ public class SpawnPool : Base
|
||||
public static SpawnPool intance;
|
||||
|
||||
public ObJPool<GameObject> EnemyPool = new ObJPool<GameObject>();
|
||||
|
||||
public List<GameObject> Enemys = new List<GameObject>();
|
||||
|
||||
[Header("生成预制体")]
|
||||
public GameObject Prefab;
|
||||
@ -91,11 +92,11 @@ public class SpawnPool : Base
|
||||
// 获取所有带有 SortingGroup 组件的物体
|
||||
List<GameObject> gameObjectsList = new List<GameObject>();
|
||||
|
||||
foreach (GameObject go in EnemyPool.SurvivalPool)
|
||||
foreach (GameObject go in Enemys)
|
||||
{
|
||||
// 获取该物体上的 SortingGroup 组件
|
||||
SortingGroup sortingGroup = go.GetComponent<SortingGroup>();
|
||||
if (sortingGroup != null)
|
||||
if (sortingGroup != null&&go.activeSelf)
|
||||
{
|
||||
// 添加到列表中
|
||||
gameObjectsList.Add(go);
|
||||
@ -112,7 +113,7 @@ public class SpawnPool : Base
|
||||
if (sortingGroup != null)
|
||||
{
|
||||
// 设置 sortingOrder 来决定显示的层级
|
||||
sortingGroup.sortingOrder = gameObjectsList.Count - i;
|
||||
sortingGroup.sortingOrder = gameObjectsList.Count - i+2;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -194,8 +195,8 @@ public class SpawnPool : Base
|
||||
}
|
||||
|
||||
enemy = Instantiate(Prefab);
|
||||
EnemyPool.SurvivalPool.Add(enemy);
|
||||
|
||||
//EnemyPool.SurvivalPool.Add(enemy);
|
||||
Enemys.Add(enemy);
|
||||
}
|
||||
|
||||
// 设置敌人的位置和其他属性
|
||||
@ -212,7 +213,7 @@ public class SpawnPool : Base
|
||||
{
|
||||
enemy.SetActive(false); // 禁用敌人对象
|
||||
EnemyPool.Return(enemy); // 将敌人回收到池中
|
||||
|
||||
Enemys.Remove(enemy);
|
||||
deadNumber++;
|
||||
if (deadNumber>= GenerateQuantityMax)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user