Can't play audio clip in inheriting javascript class

Hello there,

I’ve got the following scripts :

BonusController.js

var bonusSound : AudioClip ;

public function OnTriggerEnter (hit : Collider) : IEnumerator 
{ 
 if (hit.collider.tag =="Ship")
 { 
 audio.PlayOneShot(bonusSound); 
    
    SpecificBonusWork(hit);       
     
    Destroy(gameObject);
    }        
}

function SpecificBonusWork(hit : Collider)
{
 print("must be overriden by subclass");
}

@script RequireComponent(AudioSource)

BonusShieldController.js :

class BonusShieldController extends BonusController
{
 function SpecificBonusWork(hit : Collider)
 {
 var shieldControllerScript : ShieldController = hit.gameObject.GetComponent(ShieldController);
 shieldControllerScript.isShieldUp = true;
 shieldControllerScript.shieldType++;
 }
}

BonusShieldController.js is affected to the BonusShield gameObject and I’ve affected an Audioclip via the Inspector to the bonusSound AudioClip public variable.

When a BonusShield game object is hit by the game Object named “Ship” everything works fine, except that the bonusSound is not played.
I’ve spent time over this concern, but I really don’t figure out where the problem is from. I’ve unchecked 3D sound field of the audio file, but it doesn’t change anything.

Thanks in advance for your suggestions.

I imagine it is because you are destroying the gameObject in the same frame as you play the sound. Instead of adding a co-routine, I would suggest using PlayClipAtPoint :

http://docs.unity3d.com/Documentation/ScriptReference/AudioSource.PlayClipAtPoint.html

this way, an empty gameObject is created, plays the sound, then gets destroyed itself.