Play

What it does: Starts playing the choosen sound and returns an AudioError (see Possible Errors), showing wheter and how playing the sound 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
  • Child is the ChildType that we want to call this method on
string soundName = "SoundName";
ChildType child = ChildType.PARENT;

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

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

string soundName = "SoundName";

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

When to use it: When you want to play a sound directly without changing its initally properties.

Remarks: If you want to enable looping for a sound (see Adding a new sound) for more information. See AudioSource.Play for more details on what play does.