Esempio n. 1
0
        void NormalAttack()
        {
            anim.SetTrigger("normalAttack");
            FPSCamPerHero.FPSCamAct(E_ControlParam.NormalAttack);

            List <Hero> enemyHeroes        = TeamInfo.GetInstance().EnemyHeroes;
            Ray         ray                = Camera.main.ScreenPointToRay(screenCenterPoint);
            Vector3     normalAttackVector = ray.direction * normalAttackLength;

            for (int i = 0; i < enemyHeroes.Count; i++)
            {
                Hero    enemy         = enemyHeroes[i];
                Vector3 enemyPosition = enemy.CenterPos - ray.origin;
#if UNITY_EDITOR
                Debug.DrawLine(ray.origin,
                               ray.origin + normalAttackVector,
                               Color.blue,
                               3f
                               );
                Debug.DrawLine(ray.origin,
                               ray.origin + enemyPosition,
                               Color.red,
                               3f
                               );
#endif

                float dot = Vector3.Dot(enemyPosition, normalAttackVector);
                if (dot < Mathf.Epsilon)
                {
                    MyDebug.Log(enemy.photonView.ViewID + "HH NA enemy Behind, no attack");
                    continue;
                }
                float projectedDis = dot * normalAttackLengthDiv;
#if UNITY_EDITOR
                Debug.DrawLine(
                    ray.origin + Vector3.right * 0.1f,

                    ray.origin + Vector3.right * 0.1f + ray.direction * projectedDis,
                    Color.white, 3f
                    );
                Debug.DrawLine(
                    ray.origin + Vector3.left * 0.1f,

                    ray.origin + Vector3.left * 0.1f + ray.direction * normalAttackLength,
                    Color.green, 3f
                    );
#endif

                if (projectedDis > normalAttackLength)
                {
                    MyDebug.Log(enemy.photonView.ViewID + "HH NA enemy too far, no attack");
                    continue;
                }
                float projectedDisSqr  = projectedDis * projectedDis;
                float orthogonalDisSqr = enemyPosition.sqrMagnitude - projectedDisSqr;
#if UNITY_EDITOR
                Debug.DrawLine(
                    ray.origin + ray.direction * projectedDis,
                    ray.origin + ray.direction * projectedDis +
                    (enemy.CenterPos - (ray.origin + ray.direction * projectedDis))
                    .normalized
                    * Mathf.Sqrt(orthogonalDisSqr),
                    Color.magenta, 3f
                    );

                Debug.DrawLine(
                    ray.origin + ray.direction * projectedDis + ray.direction * 0.1f,
                    ray.origin + ray.direction * projectedDis + ray.direction * 0.1f +
                    (enemy.CenterPos + ray.direction * 0.1f - (ray.origin + ray.direction * projectedDis + ray.direction * 0.1f))
                    .normalized
                    * Mathf.Sqrt(correctionRangeSqr),
                    Color.green, 3f
                    );
#endif
                if (orthogonalDisSqr > correctionRangeSqr)
                {
                    Debug.Log(enemy.photonView.ViewID + "HH NA enemy orthogonalDis too far, no attack");
                    continue;
                }
                enemy.photonView.RPC("GetDamaged", Photon.Pun.RpcTarget.All, normalAttackDamage, photonView.ViewID);
            }
        }