I have a Audiofile that is not played on Script execution, the debuglog is printed to the console and if I choose the “PlayOnAwake” Option the sound is also played on Awake.
The script is an easyone and used as a base for a lot of other audiofiles and they are all working but not this one, what´s wrong here?
I dont see a problem with the code, maybe I am overlooking it but one thing you could try is something like this instead.
var ClipToPlay : AudioClip;
//
var keyShield : GameObject;
//
function OnTriggerEnter(other : Collider)
{
//
if(FPSWalker.grounded == true && other.gameObject.tag == "Player")
{
if(PlayerPrefs.GetInt("sound") == 1)
{
Debug.Log("CollectKey Sound Played");
audio.PlayOneShot(ClipToPlay);
}
//
Destroy (gameObject);
Destroy (keyShield);
}
}
if that does not work, It might be because you are destroying the gameobject too soon? Which has the AudioSource attached to it? try to //Destroy just to see if it will play then.