Esempio n. 1
0
    void Fire()
    {
        if (!canFire)
        {
            audioSource.PlayOneShot(emptySound);
        }

        if (canFire && !interShotCoolDown)
        {
            audioSource.PlayOneShot(Extensions.GetRandomElement(shotSounds));
            interShotCoolDown = true;
            Invoke("resetInterShotCooldown", timeBetweenShots);
            magazineCount -= 1;
            spawnShootFx();

            for (int i = 0; i < shotCount; i++)
            {
                Vector3 forward = cam.transform.forward;
                Vector3 face    = cam.transform.position;

                Vector3 dir = (forward + UnityEngine.Random.insideUnitSphere * spread);

                RaycastHit hit;

                if (Physics.Raycast(face, dir, out hit, range, ~IgnoreMe))
                {
                    Debug.DrawLine(face, hit.point, Color.grey, 2);

                    if (hit.collider.CompareTag("zombie"))
                    {
                        ZombieController zombie = hit.transform.gameObject.GetComponent <ZombieController>();

                        zombie.damageZombie(damage);

                        zombie.DisableNavmeshAgentForSeconds();

                        Rigidbody rb = hit.transform.gameObject.GetComponent <Rigidbody>();

                        rb.AddForce(forward * knockback, ForceMode.Impulse);
                    }

                    //Debug.Log("Fired: " + i.ToString() + " " + face.ToString() + " " + dir.ToString() + hit.transform.position.ToString());
                }
            }
            camShake.shakeCam();
            UpdateAmmoUI();
        }
    }