Play OneShot

What it does: Starts playing the choosen sound once and returns an AudioError (see Possible Errors), showing wheter and how playing the sound once failed.

Possible Errors:

  • DOES_NOT_EXIST
  • MISSING_WRAPPER
  • MISSING_SOURCE
  • MISSING_CLIP

How to call it:

  • SoundName is the name we have given the sound we want to play once
  • Child is the ChildType that we want to call this method on
string soundName = "SoundName";
ChildType child = ChildType.PARENT;

AudioError err = am.PlayOneShot(soundName, child);
if (err != AudioError.OK) {
    Debug.Log("Playing sound called: " + soundName + " once failed with error id: " + err);
}
else {
    Debug.Log("Playing sound called: " + soundName + " once succesfull");
}

Alternatively you can call the methods with less paramters as some of them have default arguments.

string soundName = "SoundName";

AudioError err = am.PlayOneShot(soundName);
if (err != AudioError.OK) {
    Debug.Log("Playing sound called: " + soundName + " once failed with error id: " + err);
}
else {
    Debug.Log("Playing sound called: " + soundName + " once succesfull");
}

When to use it: When you want to only play a sound once. Having multiple instances of the same sound running at the same time is only possible with this method.

Remarks: See AudioSource.PlayOneShot for more details on what play oneshot does.