public GetAudioClip ( bool threeD ) : |
||
threeD | bool | Use this to specify whether the clip should be a 2D or 3D clip /// the .audioClip property defaults to 3D. |
return |
IEnumerator LoadAudioClip(string url) { using (WWW www = new WWW(url)) { yield return www; if (!string.IsNullOrEmpty(www.error)) Debug.Log("Error loading audio clip: " + www.error); else { AudioClip clip = www.GetAudioClip(); AudioSource.PlayClipAtPoint(clip, Vector3.zero); } } }
void Start() { string url = "https://www.example.com/audio.wav"; StartCoroutine(LoadAudioClip(url)); } IEnumerator LoadAudioClip(string url) { using (WWW www = new WWW(url)) { yield return www; if (!string.IsNullOrEmpty(www.error)) Debug.Log("Error loading audio clip: " + www.error); else { AudioClip clip = www.GetAudioClip(true); AudioSource source = gameObject.AddComponentThis example loads an audio clip from a URL and plays it using an AudioSource component. The second parameter of GetAudioClip is set to true, which means that the clip will be streamed instead of fully loaded into memory. This can be useful for large audio files. The UnityEngine package library contains the WWW class and related functions.(); source.clip = clip; source.Play(); } } }
Returns an AudioClip generated from the downloaded data (Read Only).
public GetAudioClip ( bool threeD ) : |
||
threeD | bool | Use this to specify whether the clip should be a 2D or 3D clip /// the .audioClip property defaults to 3D. |
return |