Unity类银河恶魔城学习记录10-5 p93 Major stats and defensive stats源代码

Alex教程每一P的教程原代码加上我自己的理解初步理解写的注释,可供学习Alex教程的人参考

此代码仅为较上一P有所改变的代码

【Unity教程】从0编程制作类银河恶魔城游戏_哔哩哔哩_bilibili

CharacterStats.cs
cs 复制代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CharacterStats : MonoBehaviour
{
    [Header("Major stats")]
    public Stat strength; // 力量 增伤1点 临界值power 1% 物抗
    public Stat agility;// 敏捷 闪避 1% 临界chance 1%
    public Stat intelgence;// 1 点 魔法伤害 1点魔抗 
    public Stat vitality;//加血的

    [Header("Defensive stats")]
    public Stat maxHealth;
    public Stat armor;
    public Stat evasion;//闪避值


    public Stat damage;


    [SerializeField]private int currentHealth;


    protected virtual void Start()
    {
        currentHealth = maxHealth.GetValue();     
    }

    public virtual void DoDamage(CharacterStats _targetStats)
    {
        if (TargetCanAvoidAttack(_targetStats))
        {
            return;
        }


        int totleDamage = damage.GetValue() + strength.GetValue();

        totleDamage = CheckTargetArmor(_targetStats, totleDamage);

        _targetStats.TakeDamage(totleDamage);
    }

    private static int CheckTargetArmor(CharacterStats _targetStats, int totleDamage)
    {
        totleDamage -= _targetStats.armor.GetValue();
        totleDamage = Mathf.Clamp(totleDamage, 0, int.MaxValue);
        return totleDamage;
    }

    private bool TargetCanAvoidAttack(CharacterStats _targetStats)//设置闪避
    {
        int totleEvation = _targetStats.evasion.GetValue() + _targetStats.agility.GetValue();

        if (Random.Range(0, 100) < totleEvation)
        {
            return true;
        }
        return false;
    }

    protected virtual void TakeDamage(int _damage)
    {
        currentHealth -= _damage;

        Debug.Log(_damage);

        if (currentHealth < 0)
            Die();
        
    }

    protected virtual void Die()
    {

    }
}
相关推荐
辰海Coding7 小时前
MiniSpring框架学习笔记-解决循环依赖的简化IoC容器
笔记·学习
晓梦林7 小时前
cp520靶场学习笔记
android·笔记·学习
心中有国也有家9 小时前
cann-recipes-infer:昇腾 NPU 推理的“菜谱集合”
经验分享·笔记·学习·算法
Upsy-Daisy9 小时前
AI Agent 项目学习笔记(八):Tool Calling 工具调用机制总览
人工智能·笔记·学习
LuminousCPP10 小时前
数据结构 - 线性表第四篇:C 语言通讯录优化升级全记录(踩坑 + 思考)
c语言·开发语言·数据结构·经验分享·笔记·学习
魔法阵维护师10 小时前
从零开发游戏需要学习的c#模块,第十四章(保存和加载)
学习·游戏·c#
_李小白11 小时前
【android opencv学习笔记】Day 17: 目标追踪(MeanShift)
android·opencv·学习
一只机电自动化菜鸟11 小时前
一建机电备考笔记(40) 建筑机电施工—排水管道施工(含考频+题型)
经验分享·笔记·学习·职场和发展·课程设计
2301_8187305611 小时前
numpy的学习(笔记)
学习·numpy
GHL28427109012 小时前
Logon failed, use ctrl+c to cancel basic credential prompt
学习·prompt