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;
}
}
}