Sound play on collision

In the game that I am making I have many collectables around the environment that you have to gather. I have scripts set up so when the item is collected, the gameObject is destroyed and a GUI counter is incremented.

On top of this I would like for a sound to play when you pick up a collectable. Since the object is destroyed I am not able to simply attach it to the game object for the sound does not play. So I looked on the forums and ended up doing PlayClipAtPoint.

This works but does not have the exact result that I want. The sound will play just fine, but since I am generally moving through the item and just keep going to find a new collectable, the 2-3ish seconds of sound just disappears/becomes warped by the Doppler effect.

Is there a way to have the audio “follow” the First Person Controller OR make the audio file play over the entire scene and have no falloff/Doppler effect?

Here is my currently working code:

static var FEATHERS = 0;
var pickupSound : AudioClip;

function OnControllerColliderHit(hit : ControllerColliderHit)
{
	if(hit.gameObject.tag == "featherPickup")
	{
		var feathersLEFT = 60 - FEATHERS;
				
		//play sound effect
		AudioSource.PlayClipAtPoint(pickupSound, transform.position);
		
		//increment feathers
		FEATHERS ++;
		
		//print feathers remaining
		print("Feather aquired " + feathersLEFT + " feathers remaining!");
		GameObject.Find("GUI_FeatherCount").guiText.text = ""+FEATHERS;
		
		//make feather disapear
		Destroy(hit.gameObject);

		if(FEATHERS == 60)
		{
		Application.LoadLevel(3);
		print("All feathers gathered, go to the next level!");
		return;
		}
	}
}

One solution would be to not destroy the object at all, but just hide it disabling the renderer component. Just use a boolean to check if the feather is picked up or not, so you can still use an audiosource and have the sound play like you want.

But I f I get it right, that code is on your player, so instead of trying to play the sound from the feather itself, you can just add an audiosource component to your player as a child if you already have another one and play the sound there.

Also I would make a suggestion, why don’t you use OnTriggerEnter instead of OnControllerColliderHit? It would be faster, but that is just me beign nitpicking.

Mark your sound as 2D in the import settings and/or add an audio source to your player object and simply use:

audio.PlayOneShot(pickupSound);

Marking your sound as 2D will make it play at all times regardless of distance and be unaffected by the doppler effect.

I opted for the first answer of adding an audio source to the player object and using PlayOneShot. It works exactly as I want it to, thank you so very much.

As for the second answer, I made the script straight off of a tutorial pretty much and they just happened to use OnControllerColliderHit. And I am new to Unity scripting as well, so don’t know anywhere close to all the tricks yet. Also, I just like to destroy the object to make the game more “efficient” by not having as many things in the game, even though my game is very small.

Again thank you both for your answers, I really appreciate it.