Alex教程每一P的教程原代码加上我自己的理解初步理解写的注释,可供学习Alex教程的人参考
此代码仅为较上一P有所改变的代码
【Unity教程】从0编程制作类银河恶魔城游戏_哔哩哔哩_bilibili
EnemyStat.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.WSA;public class EnemyStat : CharacterStats
{private Enemy enemy;[Header("Level details")][SerializeField] private int leval = 1;[Range(0f, 1f)]//一个使数值设置成为一定范围的设置[SerializeField] private float percantageModifier = .4f;//设置等级和成长比例public override void DoDamage(CharacterStats _targetStats){base.DoDamage(_targetStats);}protected override void Die(){base.Die();enemy.Die();}protected override void Start(){//改变伤害和生命值//解决初始血量在升级后不满ApplyLevelModifier();enemy = GetComponent<Enemy>();base.Start();}private void ApplyLevelModifier(){Modify(strength);Modify(agility);Modify(intelligence);Modify(vitality);Modify(damage);Modify(critChance);Modify(critPower);Modify(maxHealth);Modify(armor);Modify(evasion);Modify(magicResistance);Modify(fireDamage);Modify(iceDamage);Modify(lightingDamage);}//专门对某个数值进行提升的函数private void Modify(Stat _stat){for(int i =1;i<leval;i++){float modifier = _stat.GetValue() * percantageModifier;_stat.AddModifier(Mathf.RoundToInt(modifier));}}public override void TakeDamage(int _damage){base.TakeDamage(_damage);}
}