Alex教程每一P的教程原代码加上我自己的理解初步理解写的注释,可供学习Alex教程的人参考
此代码仅为较上一P有所改变的代码
【Unity教程】从0编程制作类银河恶魔城游戏_哔哩哔哩_bilibili
Buff_Effcet.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public enum StatType
{
strength,
agility,
intelligence,
vitality,
damage,
critChance,
critPower,
maxHealth,
armor,
evasion,
magicResistance,
fireDamage,
iceDamage,
lightingDamage
}
[CreateAssetMenu(fileName = "BUff effect", menuName = "Data/Item effect/Buff effect")]
public class Buff_Effect :ItemEffect
{
private PlayerStats stats;
[SerializeField] private StatType buffType;
[SerializeField] private float buffDuration;
[SerializeField] private int buffAmount;
public override void ExecuteEffect(Transform _respawnPosition)
{
stats = PlayerManager.instance.player.GetComponent<PlayerStats>();
stats.IncreaseStatBy(buffAmount, buffDuration, StatToModify());
}
private Stat StatToModify()
{
if (buffType == StatType.strength) return stats.strength;
else if (buffType == StatType.agility) return stats.agility;
else if (buffType == StatType.intelligence) return stats.intelligence;
else if (buffType == StatType.vitality) return stats.vitality;
else if (buffType == StatType.damage) return stats.damage;
else if (buffType == StatType.critChance) return stats.critChance;
else if (buffType == StatType.critPower) return stats.critPower;
else if (buffType == StatType.maxHealth) return stats.maxHealth;
else if (buffType == StatType.armor) return stats.armor;
else if (buffType == StatType.evasion) return stats.evasion;
else if (buffType == StatType.magicResistance) return stats.magicResistance;
else if (buffType == StatType.fireDamage) return stats.fireDamage;
else if (buffType == StatType.iceDamage) return stats.iceDamage;
else if (buffType == StatType.lightingDamage) return stats.lightingDamage;
return null;
}
}
CharacterStats.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CharacterStats : MonoBehaviour
{
private EntityFX fx;
[Header("Major stats")]
public Stat strength; // 力量 增伤1点 爆伤增加 1% 物抗
public Stat agility;// 敏捷 闪避 1% 闪避几率增加 1%
public Stat intelligence;// 1 点 魔法伤害 1点魔抗
public Stat vitality;