怪物正常死亡

This commit is contained in:
shurongsen 2024-12-09 23:48:01 +08:00
parent 5a1e673363
commit cb20481357
2 changed files with 57 additions and 3 deletions

View File

@ -27,13 +27,15 @@ public class ObJPool<T>
if (SurvivalPool.Contains(obj))
{
SurvivalPool.Remove(obj);
DeathPool.Add(obj);
DeathPool.Add(obj);
}
}
}
public class SpawnPool : Base
{
public static SpawnPool intance;
public ObJPool<GameObject> EnemyPool = new ObJPool<GameObject>();
[Header("生成预制体")]
@ -65,6 +67,11 @@ public class SpawnPool : Base
private bool isWaveComplete = false; // 标记当前波是否完成
// Start is called before the first frame update
private void Awake()
{
intance = this;
}
void Start()
{
Base.GlobalObj.GetComponent<gameGlobal>().OnGamePlay += this.StartSpawning;

View File

@ -27,13 +27,60 @@ public class enemy : Role
public override void die()
{
if (Application.isPlaying)
{
{
// 将当前敌人对象放入死亡池
SpawnPool spawnPool = Base.GlobalObj.GetComponent<SpawnPool>(); // 获取 SpawnPool 组件
SpawnPool spawnPool = SpawnPool.intance; // 获取 SpawnPool 组件
if (spawnPool != null)
{
Debug.LogError(this.name+"die");
spawnPool.ReturnEnemyToPool(this.gameObject); // 回收当前敌人到池中
ResetAllStatus();
}
}
}
/// <summary>
/// 重置角色所有状态
/// </summary>
public void ResetAllStatus()
{
// 重置血量
Hp = 100f;
// 重置攻击力
Attack = 10f;
// 重置护甲
physicalArmor = 10;
magicArmor = 5;
// 重置等级
Level = 1;
// 重置金币
Gold = 10f;
// 清空 Buff 列表
buffList.Clear();
// 如果有导航组件,停止当前的导航行为
if (Navigation != null)
{
//Navigation.Stop(); // 假设你有 Stop 方法来停止导航
}
// 重置角色动画
animationHighlight = 0;
isAnimationPlay = false;
// 重置碰撞体(根据需求是否需要调整)
if (mycollider != null)
{
mycollider.enabled = true; // 启用碰撞体
}
// 如果有其他需要重置的状态,可以在这里添加
}
}