我正在尝试在运行时将已创建的 FBX 对象加载到场景中,我四处搜索发现可以使用assetbundle 来执行此操作。我尝试了这段代码,但它似乎没有实例化场景中的对象,也没有弹出错误。
这是代码
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)
}
}
我添加了一个新的空游戏对象,将 C# 代码拖到该游戏对象,提供了资产包链接“file://C:/Users/Sahibzada/Documents/New Unity Project/Assets/100777102370.FBX”但没有运气
有人可以指导我,代码有什么问题,我对 Unity 中的脚本完全陌生,谢谢