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--; }
private void ShootCiv(GameObject civ) { print("I hit: " + civ.transform.name + " who is a civ"); GetShot getShot = civ.GetComponent <GetShot>(); if (!getShot.haveIBeenShot) { GM.numberOfCiviliansShot++; } getShot.Shot(); }
private void ShootEnemy(GameObject enemy) { print("I hit: " + enemy.transform.name + " who is an enemy"); GetShot getShot = enemy.GetComponent <GetShot>(); if (!getShot.haveIBeenShot) { GM.numberOfEnemiesShot++; } getShot.Shot(); }