我正在尝试在运行时将已创建的FBX对象加载到场景中
我的代码在这里
void Start()
{
string url = "http://everyday3d.com/unity3d/obj/monkey.obj";
StartCoroutine(DownloadAssetBundle<GameObject>("monkey", url, 1));
}
public IEnumerator DownloadAssetBundle<T>(string asset, string url, int version) where T : UnityEngine.Object
{
using(WWW www = WWW.LoadFromCacheOrDownload (url, version))
{
yield return www;
if (www.error != null)
throw new Exception(www.error);
AssetBundle assetBundle = www.assetBundle;
var Object = assetBundle.LoadAsset(asset, typeof(T));
Instantiate(Object);
assetBundle.Unload(false);
}
}
我有错误
NullReferenceException: Object reference not set to an instance of an object
Loader+<DownloadAssetBundle>c__Iterator0`1[UnityEngine.GameObject].MoveNext () (at Assets/Script/Loader.cs:24)
我发现它是什么,因为www.assetBundle == null 解决这个问题的任何想法都有?阅读论坛,我意识到我的代码如正常。
答案 0 :(得分:0)
因为您的代码显然是为了下载资产包而不是单个资产,正如您尝试的那样。此外,.obj
不是.fbx
您是否尝试过:
WWW www = new WWW ("http://everyday3d.com/unity3d/obj/monkey.obj");
yield return www;