示例#1
0
    void Fire()
    {
        shoot = true;

        if (WeaponName.Equals("Triple Threat"))
        {
            myanim.SetBool("shoot", true);
            MouseLook.GetInstanse().Recoil(Random.Range(10, upRecoil), Random.Range(-sideRecoil, sideRecoil));
            float dist;
            float currentdamage = 0;
            for (int bullet_counter = 10; bullet_counter > 0; bullet_counter--)
            {
                CastPoint.transform.localRotation = Quaternion.identity;
                CastPoint.transform.localRotation = Quaternion.Euler(castPointStart.localRotation.x + Random.Range(-6, 6), castPointStart.localRotation.y + Random.Range(-6, 6), castPointStart.localRotation.z + Random.Range(-6, 6));
                Vector3 fwd = CastPoint.transform.TransformDirection(Vector3.forward);
                if (Physics.Raycast(CastPoint.transform.position, fwd, out hit, distance))
                {
                    //Debug.Log(hit.point);
                    //hit_p = Instantiate(hit_particles, hit.point, Quaternion.FromToRotation(Vector3.forward, castPointStart.forward));
                    hit_p = PhotonNetwork.Instantiate("Bullethole", hit.point, Quaternion.identity, 0);
                    StartCoroutine(DestroyHits(timeOnDestroy, hit_p.GetPhotonView()));

                    Rigidbody rb = hit.transform.GetComponent <Rigidbody>();
                    if (rb != null && !rb.isKinematic && rb.constraints == RigidbodyConstraints.None)
                    {
                        rb.AddForceAtPosition(CastPoint.transform.forward * power, hit.point);
                    }


                    if (hit.collider.tag == "Player")
                    {
                        ingameui.DoHitMarker();
                        dist = Vector3.Distance(transform.position, hit.collider.transform.position);

                        currentdamage += Mathf.Round(damage / dist / 5);



                        hit.transform.root.GetComponent <PhotonView>().RPC("ApplyPlayerDamage", RpcTarget.All, currentdamage, PhotonNetwork.LocalPlayer, WeaponName);
                    }
                }
            }
            //Debug.Log("uron " + currentdamage);
        }
        else
        {
            myanim.SetBool("shoot", true);
            MouseLook.GetInstanse().Recoil(Random.Range(0, upRecoil), Random.Range(-sideRecoil, sideRecoil));
            // MouseLook.GetInstanse().Recoil(upRecoil, sideRecoil);
            //Ray ray = new Ray(CastPoint.transform.position, transform.TransformDirection(Vector3.forward) * distance);

            CastPoint.transform.localRotation = Quaternion.identity;
            if (WeaponName != "PM")
            {
                CastPoint.transform.localRotation = Quaternion.Euler(castPointStart.localRotation.x + Random.Range(-3, 3), castPointStart.localRotation.y + Random.Range(-4, 4), castPointStart.localRotation.z + Random.Range(-6, 6));
            }
            else
            {
                CastPoint.transform.localRotation = Quaternion.Euler(castPointStart.localRotation.x + Random.Range(-3, 3), castPointStart.localRotation.y + Random.Range(-2, 2), castPointStart.localRotation.z + Random.Range(-6, 6));
            }
            Vector3 fwd = CastPoint.transform.TransformDirection(Vector3.forward);
            if (Physics.Raycast(CastPoint.transform.position, fwd, out hit, distance))
            {
                //hit_p = Instantiate(hit_particles, hit.point, Quaternion.FromToRotation(Vector3.forward, castPointStart.forward));
                hit_p = PhotonNetwork.Instantiate("Bullethole", hit.point, Quaternion.identity, 0);
                StartCoroutine(DestroyHits(timeOnDestroy, hit_p.GetPhotonView()));
                Rigidbody rb = hit.transform.GetComponent <Rigidbody>();
                if (rb != null && !rb.isKinematic && rb.constraints == RigidbodyConstraints.None)
                {
                    rb.AddForceAtPosition(CastPoint.transform.forward * power, hit.point);
                }
                Debug.Log("Shoot: " + hit.collider.name);
                if (hit.collider.tag == "Player")
                {
                    ingameui.DoHitMarker();
                    Debug.Log(hit.collider.name);
                    hit.transform.root.GetComponent <PhotonView>().RPC("ApplyPlayerDamage", RpcTarget.All, damage, PhotonNetwork.LocalPlayer, WeaponName);
                }
            }
            else
            {
                Debug.Log("Miss");
            }

            shell = Instantiate(currentshellPref, currentshellspawn.position, currentshellspawn.rotation);
            shell.GetComponent <Rigidbody>().AddForce(shell.transform.right * shellPower, ForceMode.Impulse);
            Destroy(shell, 2f);
        }
        // if (recoil)
        //Recoil();
    }