Beispiel #1
0
    public override void Fire()
    {
        magazine--;

        // Play gunshot sound
        weaponAudio.PlayOneShot(firingAudioClip);

        // Play muzzle flash particles
        muzzleFlashSystem.Play();

        // Check for impact. If present, continue.
        RaycastHit hit;

        if (!Physics.Raycast(playerCamera.transform.position, playerCamera.transform.forward, out hit, Mathf.Infinity))
        {
            return;
        }

        // Spawn impact particles, destroy after animation is over
        GameObject particles = Instantiate(bulletImpactPrefab, hit.point, Quaternion.LookRotation(hit.normal));

        Destroy(particles, particles.GetComponent <ParticleSystem>().main.duration);

        // Check if a zombie was hit
        if (hit.collider.gameObject.tag == "Zombie")
        {
            ZombieHealthScript zombie = hit.collider.gameObject.GetComponent <ZombieHealthScript>();

            // Zombie takes numerical damage
            zombie.TakeDamage(bulletDamage);

            // Type of force to inflict on zombie ragdoll (on killing blow)
            zombie.TakeBulletForce(-hit.normal * bulletForceMultiplier, hit.point);
        }
    }
Beispiel #2
0
    IEnumerator FuseExplode(GameObject grenade)
    {
        yield return(new WaitForSeconds(fuse));

        // Play explosion sound at grenade's location with separate AudioSource
        AudioSource.PlayClipAtPoint(explosionClip, grenade.transform.position);

        // Check all colliders inside damage radius
        Collider[] hitColliders = Physics.OverlapSphere(grenade.transform.position, damageRadius);
        foreach (Collider c in hitColliders)
        {
            // Call TakeDamage in all MonoBehaviours that have it
            c.SendMessage("TakeDamage", damage, SendMessageOptions.DontRequireReceiver);

            // Check if we hit a zombie
            ZombieHealthScript zombie = c.GetComponent <ZombieHealthScript>();
            if (zombie == null)
            {
                continue;
            }

            zombie.TakeExplosiveForce(explosionForce, grenade.transform.position, explosionRadius, explosionLift);
        }

        // Create explosion particles and destroy afterwards
        GameObject explosion = Instantiate(explosionPrefab, grenade.transform.position, Quaternion.LookRotation(Vector3.up));

        Destroy(explosion, explosion.GetComponent <ParticleSystem>().main.duration);

        // Destroy the thrown grenade
        Destroy(grenade);
        yield break;
    }
 private void Awake()
 {
     healthScript = transform.root.GetComponent <ZombieHealthScript>();
     if (healthScript == null)
     {
         Debug.LogError("Zombie Health Script not found!");
     }
 }