Making AudioSource follow camera?

For the game I am creating, when I “reload” my gun I want to play a sound clip of a gun reloading. I have done this, the problem is is that when I play the sound the sound does not follow the camera, it plays at the point I activated it. Play() for JS does not work, so I am using PlayClipAtPoint().

Here is my variable for the sound :

var reloadSound : AudioClip;

And here is my code that plays the sound :

function Reload () {
	
	if (currentClip > clipSize)
		currentClip = clipSize;
	
	if (Input.GetKeyDown("r") && !reloading && currentClip < clipSize && currentTotalBullets > 0) {
	{
		reloading = true;
		AudioSource.PlayClipAtPoint(reloadSound, transform.position, 1);
		}
	if (Input.GetButtonDown("Fire1") && currentClip == 0 && currentTotalBullets > 0)
	{
		reloading = true;
		AudioSource.PlayClipAtPoint(reloadSound, transform.position, 1);
		}

If you can help, that would be great!

Hmm… this looks like something simple to fix.

  1. Make sure the sound effect’s audio file is checked to be a “3D” sound, otherwise it will play at it’s default, original format/output.
  2. What is this “reload” script attached to? Your playclipatpoint function is playing the sound at “transform.position”. If this reload script isn’t attached to the camera objecct, then it is NOT using the cameras position but instead whatever the script is attached to. If this script is attached to something besides the game object, then it is using that objects position instead of the camera.

I seen your reply as well, you do not have to make a sound effect a child of the camera. You can load it directly into the camera with a script attached to the camera. I’m not sure what your code is attached to at the moment, but if this script is attached to the camera, then your sound should be playing at the camera’s position like I said earlier.

If you wanted sound to play from a different object (which isn’t a bad idea), you will have to load the camera as a game object into that object and then load the scripting from it so you can use the transform.position of the camera. I hope that leads you in the right direction. I do alot of sound in Unity so it shouldn’t be too difficult.