Example #1
0
    /// <summary>
    /// 检测子弹的范围碰撞.
    /// </summary>
    void CheckAmmoOverlapSphereHit(Transform posTr = null)
    {
        bool    isDestroyAmmo = false;
        Vector3 pos           = posTr == null ? transform.position : posTr.position;

        Collider[] hits = Physics.OverlapSphere(pos, ShaShangDis, AmmoHitLayer);
        for (int i = 0; i < hits.Length; i++)
        {
            // Don't collide with triggers
            if (hits[i].isTrigger)
            {
                continue;
            }

            DaoJuCtrl daoJuCom = hits[i].GetComponent <DaoJuCtrl>();
            if (daoJuCom != null && daoJuCom.DaoJuState == DaoJuCtrl.DaoJuType.ZhangAiWu)
            {
                daoJuCom.OnDestroyThis();
                isDestroyAmmo = true;
            }

            NpcController npcCom = hits[i].GetComponent <NpcController>();
            if (npcCom != null)
            {
                npcCom.OnDaoDanHit(transform.position);
                isDestroyAmmo = true;
            }

            npcScript npcSp = hits[i].GetComponent <npcScript>();
            if (npcSp != null)
            {
                npcSp.OnDestroyThis();
                isDestroyAmmo = true;
            }
        }

        if (isDestroyAmmo)
        {
            OnDestroyThis();
        }
    }
Example #2
0
    /// <summary>
    /// 检测子弹的范围碰撞.
    /// </summary>
    void CheckAmmoOverlapSphereHit(Transform posTr = null)
    {
        bool    isDestroyAmmo = false;
        Vector3 pos           = posTr == null ? transform.position : posTr.position;

        Collider[] hits = Physics.OverlapSphere(pos, ShaShangDis, AmmoHitLayer);
        for (int i = 0; i < hits.Length; i++)
        {
            // Don't collide with triggers
            if (hits[i].isTrigger)
            {
                continue;
            }

            DaoJuCtrl daoJuCom = hits[i].GetComponent <DaoJuCtrl>();
            if (daoJuCom != null && daoJuCom.DaoJuState == DaoJuCtrl.DaoJuType.ZhangAiWu)
            {
                if (PlayerController.GetInstance() != null)
                {
                    PlayerController.GetInstance().NetSendAmmoHitZhangAiWuInfo(daoJuCom);
                }
                daoJuCom.OnDestroyThis();
                isDestroyAmmo = true;
            }

            NpcController npcCom = hits[i].GetComponent <NpcController>();
            if (npcCom != null)
            {
                npcCom.OnDaoDanHit(transform.position);
                isDestroyAmmo = true;
            }

            npcScript npcSp = hits[i].GetComponent <npcScript>();
            if (npcSp != null)
            {
                npcSp.OnDestroyThis();
                isDestroyAmmo = true;
                break;
            }

            PlayerController playerScript = hits[i].GetComponent <PlayerController>();
            if (playerScript != null && IsNetControlPort)
            {
                playerScript.OnAmmoHitPlayer();
            }
        }

        if (AmmoState == AmmoType.DiLei || AmmoState == AmmoType.TankPaoDan)
        {
            //地雷和坦克炮弹强制删除.
            isDestroyAmmo = true;
        }

        if (!IsNetControlPort)
        {
            //非主控制端时,由主控制端来删除网络子弹.
            isDestroyAmmo = false;
        }

        if (isDestroyAmmo)
        {
            OnDestroyThis();
        }
    }