Trying to make a Public method/function to Play audio clips
In the game, I'm working on I use the same 2 lines of coed all the time.
this.GetComponent<AudioSource>().clip = clip;
this.GetComponent<AudioSource>().Play();
So I'm trying to make it where I can just call like playSound('SND CLP NAME') from all my other scripts, and I seem to be getting lost. I can't use this. operator thing, and I can't seem to find any information on this. i might have just overlooked something. I most likely have, so anyone able to point me in the right direction would be very appreciated MY code right now
public class MyFunctions : MonoBehaviour
{
public static void Snd(AudioClip clip)
{
//play the button clikc SFX
this.GetComponent<AudioSource>().clip = clip;
this.GetComponent<AudioSource>().Play();
}
}
Note the code is just copy pasted from when i made the function in another class.
Your answer
Follow this Question
Related Questions
How to Send Audio Clip Via Facebook Messenger ? 0 Answers
Playing many AudioSources 1 Answer
Second AudioClip won't play 0 Answers
My sound effect is not playing 0 Answers
How to make an editor extension to unity ui for switching audio clips? 0 Answers