IEnumerator CreateBullet() { yield return(new WaitForSeconds(0.1f)); audioManager.PlayShootSound(); GameObject bullet = Instantiate(bulletPrefab); int layerMask = 1 << 8; layerMask = ~layerMask; RaycastHit hit; if (Physics.Raycast(cameraObject.transform.position, cameraObject.transform.forward, out hit, Mathf.Infinity, layerMask)) { Debug.DrawLine(cameraObject.transform.position, hit.point, Color.magenta); bullet.transform.position = bulletSpawn.position; bullet.transform.LookAt(hit.point); } else { Vector3 point = cameraObject.transform.position + (cameraObject.transform.forward * 1000); bullet.transform.position = bulletSpawn.position; bullet.transform.LookAt(point); } shootLock = false; //Debug.Break(); yield return(null); }