Пример #1
0
    public void shoot()
    {
        if (currentMag > 0)
        {
            RaycastHit hit;
            currentMag      -= 1;
            currentMagT.text = "" + currentMag;
            //audS.PlayOneShot(gunShot);

            if (Physics.Raycast(shootPos.transform.position, shootPos.transform.forward, out hit, range))
            {
                //Debug.Log(hit.transform.name);

                Health health = hit.transform.GetComponent <Health>();
                if (health != null)
                {
                    health.takeDamage(damage);
                }

                GameObject impactGO     = Instantiate(bulletHitGO, hit.point, Quaternion.LookRotation(hit.normal));
                GameObject bulletHoleGO = Instantiate(bulletHole, hit.point, Quaternion.LookRotation(hit.normal));
                bulletHoleGO.transform.parent = hit.collider.transform;
                Destroy(impactGO, 2.5f);
                Destroy(bulletHoleGO, 60.0f);
            }

            StartCoroutine(flash());
            recoil.camRecoil(verticalRecoil, horizontalRecoil);
        }

        else
        {
            print("RELOAD");
        }
    }