i am trying to load an already created FBX object into the scene at runtime, i searched around and found that assetbundle can be used to do so. I tried this code but it doesnt seem to instantiate the object in the scene and neither does it pop an error.
Here is the code
using System;
using UnityEngine;
using System.Collections;
public class CachingLoadExample : MonoBehaviour {
public string BundleURL;
public string AssetName;
public int version;
void Start() {
StartCoroutine (DownloadAndCache());
}
IEnumerator DownloadAndCache (){
// Wait for the Caching system to be ready
while (!Caching.ready)
yield return null;
// Load the AssetBundle file from Cache if it exists with the same version or download and store it in the cache
using(WWW www = WWW.LoadFromCacheOrDownload (BundleURL, version)){
yield return www;
if (www.error != null)
throw new Exception("WWW download had an error:" + www.error);
AssetBundle bundle = www.assetBundle;
if (AssetName == "")
Instantiate(bundle.mainAsset);
else
Instantiate(bundle.Load(AssetName));
// Unload the AssetBundles compressed contents to conserve memory
bundle.Unload(false);
} // memory is freed from the web stream (www.Dispose() gets called implicitly)
}
}
I added a new empty game object, dragged the C# code to that game object, supplied the asset bundle link "file://C:/Users/Sahibzada/Documents/New Unity Project/Assets/100777102370.FBX" but no luck
Can someone please guide me, whats wrong with the code, i am totally new with scripting in Unity, Thanks
Caching.isReadyis never returning true? Also: are you sure you're using Unity Pro? It's required for use with asset bundles. - rutter