Click or drag to resize

UISoundPlayerPlay Method

Plays the specified sound.

Namespace:  KSPDev.GUIUtils
Assembly:  KSPDev_Utils.2.0 (in KSPDev_Utils.2.0.dll) Version: 2.0 for KSP v1.8+
Syntax
C#
public void Play(
	string audioPath
)
Request Example View Source

Parameters

audioPath
Type: SystemString
The file path relative to GameData. It can be empty, in which case nothing is played.
Remarks
Every request is cached, so that the subsequent calls to play the same sound won't require the audio clip to load. However, the same cached sound cannot be played simultaneously from the different calls - each call will abort the previous play action of the sound.
Examples
public class UISoundPlayerDemo1 : PartModule {
  public override void OnAwake() {
    // To not loose the latency on the sound play pre-cache it.
    UISoundPlayer.instance.CacheSound("ooo.ogg");
  }

  public override void OnUpdate() {
    if (Input.GetKeyDown("O")) {
       UISoundPlayer.instance.Play("ooo.ogg");  // Played from cache. No delay.
    }
    if (Input.GetKeyDown("P")) {
      UISoundPlayer.instance.Play("ppp.ogg");  // May delay the game while loading the resource.
    }
  }
}
See Also