コード例 #1
0
        //找到最近的敌人 不考虑朝向方向
        public static GameObject FindNearestEnemy(GameObject attacker)
        {
            LayerMask mask    = SkillDamageCaculate.GetDamageLayer();
            var       enemies = Physics.OverlapSphere(attacker.transform.position, attacker.GetComponent <NpcAttribute>().AttackRange, mask);
            float     minDist = 999999;

            GameObject enemy     = null;
            var        transform = attacker.transform;

            Log.Sys("EnemyCount: " + enemies.Length);
            foreach (var ene in enemies)
            {
                var npcAttr = ene.gameObject.GetComponent <NpcAttribute>();
                if (npcAttr == null)
                {
                    npcAttr = ene.gameObject.GetComponentInParent <NpcAttribute>();
                }
                Log.Sys("EnemyIs: " + npcAttr);
                if (npcAttr != null && !npcAttr.IsDead && IsEnemy(attacker, npcAttr.gameObject))
                {
                    var d = (ene.transform.position - transform.position).sqrMagnitude;
                    if (d < minDist)
                    {
                        minDist = d;
                        enemy   = ene.gameObject;
                    }
                }
            }

            return(enemy);
        }
コード例 #2
0
        /*
         * 1自己   自己的宠物
         * 2其它玩家  其它玩家的宠物
         * 3怪物
         * 4墙体
         * 5: 事件类型碰撞体不参与技能 例如入口和出口的碰撞体? (忽略这种 假设所有都会碰撞)
         *
         *
         * 对于子弹的发射者来讲
         * 按照角色分成三种:
         * 1:友方
         * 2:敌方
         * 3:中立(墙体)
         */

        private void FixedUpdate()
        {
            if (isDie)
            {
                return;
            }
            Collider[] col = Physics.OverlapSphere(transform.position, missileData.Radius,
                                                   SkillDamageCaculate.GetDamageLayer());
            foreach (Collider c in col)
            {
                //和多个不同的敌人目标碰撞
                if (c != lastColobj)
                {
                    lastColobj = c;
                    var hitT = NetworkUtil.GetAttr(c.gameObject);
                    if (hitT != null)
                    {
                        if (hitT.gameObject != this.attacker)
                        {
                            HitSomething(c);
                            break;
                        }
                    }
                    else
                    {
                        HitSomething(c);
                        break;
                    }
                }
            }
        }
コード例 #3
0
        private void Update()
        {
            if (!runner || !runner.stateMachine || !runner.stateMachine.attacker || runner.stateMachine.isStop)
            {
                return;
            }

            var me = runner.stateMachine.attacker;

            Collider[] hitColliders;
            hitColliders = Physics.OverlapSphere(me.transform.position, radius,
                                                 SkillDamageCaculate.GetDamageLayer());

            for (int i = 0; i < hitColliders.Length; i++)
            {
                var enemy = NetworkUtil.GetAttr(hitColliders[i].gameObject);
                if (enemy != null && SkillLogic.IsEnemy(me, enemy.gameObject))
                {
                    if (!hurtEnemy.Contains(enemy.gameObject))
                    {
                        var dir = enemy.transform.position - me.transform.position;
                        dir.y = 0;
                        var cos = Vector3.Dot(dir.normalized, transform.forward);
                        Log.AI("DamageHit " + runner.stateMachine.name + " " + enemy.name + " cos " + cos + " a " + cosAngle);
                        if (cos > cosAngle)
                        {
                            DoDamage(enemy.gameObject);
                            hurtEnemy.Add(enemy.gameObject);
                        }
                    }
                }
            }
            Log.AI("Check Damage Shape " + runner.stateMachine.name);
        }
コード例 #4
0
 private void AOEDamage()
 {
     Collider[] col = Physics.OverlapSphere(transform.position, missileData.AOERadius,
                                            SkillDamageCaculate.GetDamageLayer());
     foreach (Collider c in col)
     {
         DoDamage(c);
     }
 }
コード例 #5
0
 /// <summary>
 /// 显示门开启的效果
 /// </summary>
 /// <returns>The show door open effect.</returns>
 IEnumerator WaitShowDoorOpenEffect()
 {
     while (true)
     {
         var players = Physics.OverlapSphere(transform.position, 4, SkillDamageCaculate.GetDamageLayer());
         foreach (Collider p in players)
         {
             if (p.tag == GameTag.Player)
             {
                 StartCoroutine(ShowOpenEffect());
                 yield break;
             }
         }
         yield return(null);
     }
 }
コード例 #6
0
 private bool CheckHit()
 {
     Collider[] col = Physics.OverlapSphere(head.transform.position, missileData.Radius,
                                            SkillDamageCaculate.GetDamageLayer());
     foreach (Collider c in col)
     {
         //和多个不同的敌人目标碰撞
         var hitT = NetworkUtil.GetAttr(c.gameObject);
         if (hitT != null)
         {
             if (hitT.gameObject != this.attacker)
             {
                 HitSomething(hitT);
                 return(true);
             }
         }
     }
     return(false);
 }
コード例 #7
0
ファイル: DamageShape.cs プロジェクト: 79Game/GameDemo
        /// <summary>
        /// 延迟等待
        /// 判定是否是一次性伤害技能 还是持续性伤害
        ///
        /// 开始判定伤害,技能没有结束
        /// 无伤害只移动对象
        ///
        ///
        /// </summary>
        void Update()
        {
            passTime += Time.deltaTime;
            if (passTime < delayTime)
            {
                return;
            }
            if (Once && damageYet)
            {
                return;
            }
            if (!runner || !runner.stateMachine || !runner.stateMachine.attacker)
            {
                return;
            }

            if (enable && !runner.stateMachine.isStop)
            {
                if (!NoHurt)
                {
                    //物理碰撞检测 玩家附近 或者 碰撞体附近的单位
                    Collider[] hitColliders;
                    if (SyncWithPlayer)
                    {
                        hitColliders = Physics.OverlapSphere(runner.stateMachine.attacker.transform.position, radius, SkillDamageCaculate.GetDamageLayer());
                    }
                    else
                    {
                        hitColliders = Physics.OverlapSphere(transform.position, radius, SkillDamageCaculate.GetDamageLayer());
                    }

                    for (int i = 0; i < hitColliders.Length; i++)
                    {
                        if (SkillLogic.IsEnemy(runner.stateMachine.attacker, hitColliders[i].gameObject))
                        {
                            if (!hurtEnemy.Contains(hitColliders[i].gameObject))
                            {
                                if (shape == Shape.Sphere)
                                {
                                    DoDamage(hitColliders[i].gameObject);
                                    hurtEnemy.Add(hitColliders[i].gameObject);
                                }
                                else if (shape == Shape.Angle)
                                {
                                    Log.AI("DamageHit " + runner.stateMachine.name + " " + hitColliders[i].name);
                                    var dir = hitColliders[i].gameObject.transform.position - transform.position;
                                    var cos = Vector3.Dot(dir.normalized, transform.forward);
                                    if (cos > cosAngle)
                                    {
                                        DoDamage(hitColliders[i].gameObject);
                                        hurtEnemy.Add(hitColliders[i].gameObject);
                                    }
                                }
                            }
                        }
                    }
                    Log.AI("Check Damage Shape " + runner.stateMachine.name);
                    damageYet = true;
                }

                ///DamageShape 开始移动玩家 同时也移动玩家
                if (runner != null && runner.Event.attachOwner)
                {
                    Log.Sys("Move Attack With DamageShape");
                    if (!enableYet)
                    {
                        StartCoroutine(MoveOwner());
                    }
                }
                enableYet = true;
            }
        }
コード例 #8
0
        //TODO: 子弹可以和四种对象碰撞:

        /*
         * 1自己   自己的宠物
         * 2其它玩家  其它玩家的宠物
         * 3怪物
         * 4墙体
         * 5: 事件类型碰撞体不参与技能 例如入口和出口的碰撞体? (忽略这种 假设所有都会碰撞)
         *
         *
         * 对于子弹的发射者来讲
         * 按照角色分成三种:
         * 1:友方
         * 2:敌方
         * 3:中立(墙体)
         */
        void FixedUpdate()
        {
            if (isDie)
            {
                return;
            }
            Collider[] col = Physics.OverlapSphere(transform.position, missileData.Radius, SkillDamageCaculate.GetDamageLayer());
            foreach (Collider c in col)
            {
                //和多个不同的敌人目标碰撞
                if (c != lastColobj)
                {
                    lastColobj = c;
                    HitSomething(c);
                    break;
                }
            }
        }
コード例 #9
0
ファイル: AOETargetPlace.cs プロジェクト: Xnovae/MobaClient
        /// <summary>
        /// 根据BeamTargetPos 激光瞄准位置
        /// 或者MarkPos 标记位置来选择攻击目标
        /// </summary>
        /// <returns>The explosive.</returns>
        IEnumerator WaitExplosive()
        {
            yield return(new WaitForSeconds(WaitTime));

            var tarPos = Vector3.zero;

            if (AOEHere)
            {
                tarPos = transform.position;
            }
            else if (runner.BeamTargetPos != Vector3.zero)
            {
                tarPos = runner.BeamTargetPos;
            }
            else if (runner.stateMachine.MarkPos != Vector3.zero)
            {
                tarPos = runner.stateMachine.MarkPos;
            }
            if (tarPos != Vector3.zero)
            {
                transform.position = tarPos;
                if (DieParticle != null)
                {
                    GameObject g = Instantiate(DieParticle) as GameObject;
                    NGUITools.AddMissingComponent <RemoveSelf> (g);
                    g.transform.parent   = ObjectManager.objectManager.transform;
                    g.transform.position = runner.BeamTargetPos + ParticlePos;
                }

                Collider[] col = Physics.OverlapSphere(transform.position, AOERadius, SkillDamageCaculate.GetDamageLayer());
                foreach (Collider c in col)
                {
                    DoDamage(c);
                }
            }
            else
            {
                Debug.LogError("BeamTargetPos Is NULL");
            }
        }