Loading scene from assetbundle (url)

I want to load the scene using www but it fails to download and shows a null. I’m not sure why it doesn’t download.

using UnityEngine;
using System.Collections;
using AssetBundles;


public class loadingscene : MonoBehaviour
{
	public string sceneAssetBundle;
	public string sceneName;
	public string url;
	
	// Use this for initialization
	IEnumerator Start ()
	{	
		yield return StartCoroutine(Initialize() );
		
		// Load level.
		yield return StartCoroutine(InitializeLevelAsync (sceneName, true) );
	}
	
	// Initialize the downloading url and AssetBundleManifest object.
	protected IEnumerator Initialize()
	{
		// Don't destroy this gameObject as we depend on it to run the loading script.
		DontDestroyOnLoad(gameObject);
		// With this code, when in-editor or using a development builds: Always use the AssetBundle Server
		// (This is very dependent on the production workflow of the project. 
		// 	Another approach would be to make this configurable in the standalone player.)
		#if DEVELOPMENT_BUILD || UNITY_EDITOR
		AssetBundleManager.SetSourceAssetBundleURL(url);
		//	AssetBundleManager.SetDevelopmentAssetBundleServer ();
		#else
		// Use the following code if AssetBundles are embedded in the project for example via StreamingAssets folder etc:
		AssetBundleManager.SetSourceAssetBundleURL(Application.dataPath + "/");
		// Or customize the URL based on your deployment or configuration
		/AssetBundleManager.SetSourceAssetBundleURL("http://www.MyWebsite/MyAssetBundles");
		#endif
		
		// Initialize AssetBundleManifest which loads the AssetBundleManifest object.
		var request = AssetBundleManager.Initialize();
		
		if (request != null)
			yield return StartCoroutine(request);
	}
	
	protected IEnumerator InitializeLevelAsync (string levelName, bool isAdditive)
	{
		WWW www = WWW.LoadFromCacheOrDownload (url, 1);
		yield return www;
		if (www.error != null) {
			print ("WWW donwload had an error : " + url + " " + www.error);
				//Debug.Log("");
			}
		AssetBundle bundle = www.assetBundle;
		Debug.Log(www.assetBundle.mainAsset);

		// This is simply to get the elapsed time for this phase of AssetLoading.
		float startTime = Time.realtimeSinceStartup;
		
		// Load level from assetBundle.
		AssetBundleLoadOperation request = AssetBundleManager.LoadLevelAsync(sceneAssetBundle, levelName, isAdditive);
		if (request == null)
			yield break;
		yield return StartCoroutine(request);
		// Calculate and display the elapsed time.
		float elapsedTime = Time.realtimeSinceStartup - startTime;
		Debug.Log("Finished loading scene " + levelName + " in " + elapsedTime + " seconds" );
		bundle.Unload(false);
		// Frees the memory from the web stream
		www.Dispose();
	}
}

If you want to “download” the asset Bundle from the StreamingAssets folder you need to change

AssetBundleManager.SetSourceAssetBundleURL(Application.dataPath + "/");

to something like

AssetBundleManager.SetSourceAssetBundleURL(Application.streamingAssetsPath+"/");

More infos are here, here and here.

However if you want to download the Asset Bundles from the web you need to remove the / from line 36 of your posted code.

/AssetBundleManager.SetSourceAssetBundleURL("http://www.MyWebsite/MyAssetBundles");

to

AssetBundleManager.SetSourceAssetBundleURL("http://www.MyWebsite/MyAssetBundles");

Adapt the link and comment out the local call

AssetBundleManager.SetSourceAssetBundleURL(Application.dataPath + "/");

before, otherwise it looks up the local path instead of the url.