Peer Play Navigation
  • About
  • Projects
    • Visualife
    • Blind Love
    • Ripple
    • Share Hockey
    • Deciball
    • Organ
  • Visuals
  • Tutorials
    • Breaking Glass
    • Preloading External Music
    • Ripple Water Shader
    • Wobbly Grid
  • Contact

Preloading External Music


using UnityEngine;
using System.Collections;

public class LoadFile : MonoBehaviour
{

public string urlString;
public GameObject progressBar;
string url;
WWW www;
AudioClip clip;

void Update ()
{
if (www != null)
{
progressBar.transform.localScale = new Vector3(www.progress,1,1);
}
}

IEnumerator LoadURL()
{
url = urlString;
www = new WWW(url);
clip = www.GetAudioClip(false, true);

while (!www.isDone)
{
yield return www;
}

if (www.error == null)
{
audio.clip = clip;
audio.Play();
}
if (www.error != null)
{
Debug.Log("Error! Make sure you load an OGG or WAV Check the URL!");
}
yield return 0;
}

void OnGUI()
{
urlString = GUI.TextField(new Rect(10,10, 200, 20), urlString, 100);

if (GUI.Button(new Rect(10, 40, 200, 50), "Load URL"))
{
StartCoroutine(LoadURL());
}
}

}

PeerPlayPreloading External Music12.10.2014

Leave a Reply Cancel reply

Your email address will not be published.

Toggle the Widgetbar
  • About
  • Projects
  • Visuals
  • Tutorials
  • Contact