private void DoProjectile() { Transform projectileSpawnPoint = weaponGraphics.bulletTracerPosition; Transform playerFacingDirection = weaponManager.localPlayerCamera; //Figure out where the projectile should aim for RaycastHit[] hits = RaycastHelper.RaycastAllSorted(playerFacingDirection.position, playerFacingDirection.forward, float.MaxValue, weaponManager.raycastLayerMask); //We need to filter through each hit RaycastHit?raycastHit = null; foreach (RaycastHit hit in hits) { //Don't count if we hit the shooting player if (hit.collider.name == weaponManager.transform.name) { continue; } raycastHit = hit; } //Spawn the object GameObject newProjectile = projectileObjectsPool.GetPooledObject(); if (raycastHit.HasValue) { RaycastHit hit = raycastHit.Value; if (hit.distance > projectileAutoAimMinRange) { newProjectile.transform.LookAt(hit.point); Logger.Debug("Pointing player's projectile at cross-hair."); } } ProjectileBase projectile = newProjectile.GetComponent <ProjectileBase>(); if (projectile == null) { Logger.Error("Weapon projectile doesn't have a projectile base on it!"); return; } projectile.SetupOwner(weaponManager.playerManager); projectile.ServerEnable(projectileSpawnPoint.position, projectileSpawnPoint.rotation.eulerAngles); DoWeaponEffects(new ProjectileEffectsMessage()); }