Example #1
0
    IEnumerator Shoot()
    {
        muzzleFlash.Play();
        m_animator.SetTrigger("Shoot");
        soundEmitted.Play();
        RaycastHit hit;

        if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
        {
            // Prints to the console what has been hit by the raycast
            Debug.Log(hit.transform.name);

            // If the raycast hits an enemy, it will take damage
            GetShot target = hit.transform.GetComponent <GetShot>();
            if (target != null)
            {
                target.TakeDamage(damage);
            }
        }

        // Delay between shots, and subtracting the ammo count
        yield return(new WaitForSecondsRealtime(shootTime));

        isShooting = false;
        currentAmmo--;
    }