void Fire() { Game.instance.CrossAnima(); GameObject thebullet = (GameObject)Instantiate(bullet_prefab, forceShoot.transform.position, forceShoot.transform.rotation); thebullet.GetComponent <Rigidbody>().AddForce(forceShoot.transform.right * bulletImpulse, ForceMode.Impulse); animationGO.GetComponent <Animation>().CrossFadeQueued("fire", 0.08F, QueueMode.PlayNow); muzzleFlash.GetComponent <Animation>().Play("muzzleFlash"); // Fire sound if (weaponSource.clip != fireGun) { weaponSource.clip = fireGun; } weaponSource.Play(); //bullet hole Ray ray = new Ray(cameraLocation.transform.position, cameraLocation.transform.forward); if (Physics.Raycast(ray, out hit, 100f, shootableMask)) { // Try and find an EnemyHealth script on the gameobject hit. EnemyHealth enemyHealth = hit.collider.GetComponent <EnemyHealth> (); // If the EnemyHealth component exist... if (enemyHealth != null) { // ... the enemy should take damage. enemyHealth.TakeDamage(damagePerShot, hit.point); } if (hit.collider.gameObject.tag != "Enemy") { GameObject cloneBulletHole = Instantiate(bulletHole, hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal)) as GameObject; Destroy(cloneBulletHole, 1.0f); } } playerAmmo.TakeAmmo(1); }