Quantcast
Viewing all articles
Browse latest Browse all 12

Answer by kilgore

I just recently ran into the same issue and wanted to post the following code, it is basically an extenstion of what xeophin posted and I can confirm that it is working.

In this example, I have a GameObject with an AudioSource component attached and a script with a function called PlayClip. I pass the audio clips name that then loads clip from the Resources fold.

public void PlayClip(string clipName){
     AudioSource source = gameObject.GetComponent<AudioSource>();
     source.rolloffFactor = 0;
     AudioClip clip = Resources.Load(clipName)as AudioClip;
     source.clip = clip;
     audioSource.Play();
 }

note - I am making the AudioSource rolloffFactor 0 so that it can be heard everywhere without, well, fallOff. That one got me for a few minutes.


Viewing all articles
Browse latest Browse all 12

Trending Articles