• 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)
  • 相关阅读:
    JavaScript一个页面中有多个audio标签,其中一个播放结束后自动播放下一个,audio连续播放
    JavaScript多个音频audio标签或者多个视频video,点击其中一个播放时,其他的停止播放
    JavaScript多个h5播放器video,点击一个播放其他暂停
    jQuery表单2
    CSS3-渐变这个属性2
    微信小程序——扫码后提示“打开失败缺少ID”
    js隐藏button
    js 跳转链接的几种方式
    使用onclick报SyntaxError: identifier starts immediately after numeric literal
    jsp中获取attribute
  • 原文地址:https://www.cnblogs.com/XiaoLang0/p/9716914.html
Copyright © 2020-2023  润新知