Jump to content

Playing custom sound when button is clicked


Recommended Posts

Greetings! First of all i'm going to say sorry for my english, but i hope you'll undersand my question.

I have read some tutorials and tried to make an own small plugin mod.

I've created a module, which calls a GUI window with a button.

The OnClick() method cals even a button is pressed.

So now i'm trying to play custom sound in this meth.

Could you answer me where should i locate my audio file (for example - mysound.wav)?

Should it be in the module folder like a KSP/Parts/MyPart/Sounds/mysound.wav or in game recources KSP/GameData/Squad/Sounds.

What should i use to load it and play(WWW class with url linked to audio file) or Recources.Load() method)?

Should i create a new game object, wait when audio.clip.isReadyToPlay equals true and etc?

I've watched lots of posts and there are so many different ways to realise that, but nothing works.

I am grateful for any help.:blush: Thanks!

Link to comment
Share on other sites

Can't belive, but i found a solution:

WWW url = new WWW("file://" + "C:/....../Parts/TestPart/Sound/sound1.wav"); // or simply use KSPUtil.ApplicationRootPath to get ksp directory

audio.clip = url.audioClip;

while (!audio.clip.isReadyToPlay)
{

}
audio.PlayOneShot(url.audioClip);

It may be helpful!

Link to comment
Share on other sites

Where you put the file depends on how you're using it. If it's an effect for a specific part, throw it in that part's folder. If it's for general use in your mod, put it in GameData/{yourmod} or even GameData/{yourmod}/Sounds. You can use GameDatabase to load the audio clip. (It's something like GameDatabase.Instance.GetAudioClip() and you pass a KSP URL.)

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...