diff --git a/lua/app/module/battle/component/battle_unit_comp.lua b/lua/app/module/battle/component/battle_unit_comp.lua index 9174348f..3a1e626a 100644 --- a/lua/app/module/battle/component/battle_unit_comp.lua +++ b/lua/app/module/battle/component/battle_unit_comp.lua @@ -16,7 +16,6 @@ local HURT_STATE_CRIT = BattleConst.HURT_STATE_CRIT local EFFECT_TYPE = BattleConst.EFFECT_TYPE local TIME_FACTOR = BattleConst.TIME_FACTOR local HURT_ANI_NAME_LIST = {SPINE_ANIMATION_NAME.HIT, SPINE_ANIMATION_NAME.HIT_2} -local HURT_ANI_NAME_LIST_COUNT = 2 function BattleUnitComp:ctor() end @@ -114,6 +113,19 @@ function BattleUnitComp:initWithEntity(modelId, entity, battleController, target self:initPosition() self:initPassiveSkills() self:playBorn() + self:initHitAniInfo() +end + +function BattleUnitComp:initHitAniInfo() + self.hurtAniNameList = {} + self.hurtAniNameCount = 0 + for _, name in ipairs(HURT_ANI_NAME_LIST) do + local duration = self:getAnimationDuration(name) + if duration > 0 then + table.insert(self.hurtAniNameList, name) + self.hurtAniNameCount = self.hurtAniNameCount + 1 + end + end end function BattleUnitComp:prepare() @@ -692,7 +704,10 @@ end function BattleUnitComp:playHurt() if self.currState == UNIT_STATE.IDLE or self.currState == UNIT_STATE.VERITGO then - local name = HURT_ANI_NAME_LIST[math.random(1, HURT_ANI_NAME_LIST_COUNT)] + if self.hurtAniNameCount <= 0 then + return + end + local name = self.hurtAniNameList[math.random(1, self.hurtAniNameCount)] self.playSubAniTime = 0 self.curHurtName = name if self.playSubAniDuration[name] == nil then