I’m having problems with a few audio clips not playing correctly. All my clips are wav and generally less than 5 seconds long.
My sourcecode is really simple.
#pragma strict
var bonusSound : AudioClip;
function OnTriggerEnter(hit:Collider){
if(hit.tag == "Player") { // See if the impact was the player
if(bonusSound) // Check if there is a sound clip attached to this bonus
AudioSource.PlayClipAtPoint(bonusSound, transform.position, 0.1 ); // If there is, play it
}
}
This is attached to my “bonus” gameObject, which is a prefab and is located twice throughout the level. The first time it plays the audio for the first bonus, it usually works ok. Sometimes it gets cut off half way through. The second bonus almost never plays correctly. It plays for a fraction of a second (maybe 0.1 seconds), sometimes nothing at all.
I should note that I’ve tried both 2D and 3D audio for this clip.
I think it may be related to the number of sound files I have running at one time as when I remove some enemies the problem is much less likely to occur. There is about 80-130 audio clips running most of the time (and when the problem occurs), but there are areas of my level running about 170 audio clips with no problem.
This is on a PC, not a mobile so I would imagine that certainly it should be able to handle a lot more than that.
I should point out that I’ve also tried just using “audio.Play” and attaching the audio clip directly, but that has the same problem. My audio file itself is definitely ok as I’ve been using it for months now.
Is there perhaps a better way that I can be playing the sound files?