diff --git a/assets/script/game/hero/HeroViewComp.ts b/assets/script/game/hero/HeroViewComp.ts index 97f12ba3..b03a620f 100644 --- a/assets/script/game/hero/HeroViewComp.ts +++ b/assets/script/game/hero/HeroViewComp.ts @@ -170,26 +170,14 @@ export class HeroViewComp extends CCComp { /** 显示护盾 */ private show_shield(shield: number = 0, shield_max: number = 0) { - // ✅ 即使 top_node 不活跃,也要更新护盾的显示状态 - // 当护盾为0时,隐藏护盾UI - const hasShield = shield > 0 && shield_max > 0; - - this.node.getChildByName("shielded").active = hasShield; - - // 如果 top_node 活跃,才更新护盾进度条 - if (this.top_node) { - this.top_node.getChildByName("shield").active = hasShield; - - if (hasShield) { - let shield_progress = shield / shield_max; - this.top_node.getChildByName("shield").getComponent(ProgressBar).progress = shield_progress; - this.scheduleOnce(() => { - if (this.top_node && this.top_node.isValid) { - this.top_node.getChildByName("shield").getChildByName("pb").getComponent(ProgressBar).progress = shield_progress; - } - }, 0.15); - } - } + if(!this.top_node.active) return + let shield_progress = shield / shield_max; + this.node.getChildByName("shielded").active = shield > 0; + this.top_node.getChildByName("shield").active = shield > 0; + this.top_node.getChildByName("shield").getComponent(ProgressBar).progress = shield_progress; + this.scheduleOnce(() => { + this.top_node.getChildByName("shield").getChildByName("pb").getComponent(ProgressBar).progress = shield_progress; + }, 0.15); } /** 显示血量 */