zoukankan      html  css  js  c++  java
  • AttackEnemy人物攻击判断

    AttackEnemy人物攻击判断

    /// <param name="attackArea">攻击范围</param>

    /// <param name="attackPowerMultiple">攻击力度(倍率)</param>

    /// <param name="isDirection">攻击是否有方向性</param>

    protected void AttackEnemy(List<GameObject> lisEnemys, Transform traNearestEnemy, float attackArea, int attackPowerMultiple, bool isDirection = true)

    {

                //参数检查

                if (lisEnemys == null || lisEnemys.Count <= 0)

                {

                    traNearestEnemy = null;

                    return;

                }

                foreach (GameObject enemyItem in lisEnemys)

                {

                    if (enemyItem && enemyItem.GetComponent<Ctrl_BaseEnemyProperty>())

                    {

                        if (enemyItem.GetComponent<Ctrl_BaseEnemyProperty>().CurrentState != EnemyState.Death)

                        {

                            //敌我距离

                           float floDistance = Vector3.Distance(this.gameObject.transform.position, enemyItem.transform.position);

                            //攻击具有方向性

                            if (isDirection)

                            {

                                //定义“主角与敌人” 的方向

            Vector3 dir = (enemyItem.transform.position - this.gameObject.transform.position).normalized;

                                //定义“主角与敌人”的夹角(用向量的“点乘”进行计算)

            float floDirection = Vector3.Dot(dir, this.gameObject.transform.forward);

            //如果主角与敌人在同一个方向,且在有效攻击范围内,则对敌人做伤害处理

                                if (floDirection > 0 && floDistance <= attackArea)

                                {

              enemyItem.SendMessage("OnHurt", Ctrl_HeroProperty.Instance.GetCurrentATK() * attackPowerMultiple, SendMessageOptions.DontRequireReceiver);

                                }

                            }

                            //攻击无方向性

                            else

                            {

                                if (floDistance <= attackArea)

                                {

              enemyItem.SendMessage("OnHurt", Ctrl_HeroProperty.Instance.GetCurrentATK() * attackPowerMultiple, SendMessageOptions.DontRequireReceiver);

                                }

                            }

                        }

                    }

          }

    }

    注:此方法根据方向、距离进行播放不同的动画,来完成攻击,加入伤害后使用、具体套用方法请看后续代码(如有错误或运行Bug、请联系本人)...

    支持个人观看使用,如商用或转载,请告知! -----萧朗(QQ:453929789 Email:xiaolang_xl@sina.com)
  • 相关阅读:
    JQuery移除事件
    .NET经常调用的外部系统函数举例说明
    sql server日期时间转字符串
    关于无法打开微软网站的解决方法[转]
    Html5 第二章
    style、currentStyle、getComputedStyle区别介绍
    删除右键菜单中多余项
    css制作流程及标准
    CSS的选择器
    Mysql 函数集
  • 原文地址:https://www.cnblogs.com/XiaoLang0/p/9716914.html
Copyright © 2011-2022 走看看