我正在为webgl做游戏。但是,当我在链接上上传资产捆绑包,然后将其加载到游戏中时,它显示错误。
错误:无法解压缩AssetBundle“内存”的数据。UnityEngine.WWW:get_assetBundle()
NullReferenceException:对象引用未设置为对象的实例DownloadScript + d__2.MoveNext()(位于Assets / DownloadScript.cs:27)
当我从系统(本地)加载资产时,它会完美加载。但是,当我将其上传到实时链接时,它不会加载。
这是我的从服务器加载它的代码
'''
public class DownloadScript : MonoBehaviour
{
public string url;
// Start is called before the first frame update
[System.Obsolete]
void Start()
{
StartCoroutine(DownloadModel());
}
[System.Obsolete]
IEnumerator DownloadModel()
{
WWW wwws = new WWW(url);
yield return wwws;
//UnityWebRequest www = UnityWebRequest.GetAssetBundle();
//yield return www.SendWebRequest();
AssetBundle assetBundle = wwws.assetBundle;
Instantiate(assetBundle.LoadAsset("cube"));
}
'''
要从本地系统加载的代码:
'''
AssetBundle myLoadedAssetbundle;
public string path;
public string bundleAsset;
void Start()
{
LoadAssetBundle(path);
//InstantiateObjectFromBundle(bundleAsset);
StartCoroutine(DownloadAndCache(path));
}
void LoadAssetBundle(string bundleUrl)
{
myLoadedAssetbundle = AssetBundle.LoadFromFile(bundleUrl);
//myLoadedAssetbundle = AssetBundle.
Debug.Log(myLoadedAssetbundle == null ? "Failed to load AssetBundle" : "AssetBundle Succesfully Loaded");
}
void InstantiateObjectFromBundle(string assetName)
{
var prefab = myLoadedAssetbundle.LoadAsset(assetName);
Instantiate(prefab);
}
'''
您确定您还在考虑正确的平台来构建资产捆绑包吗?为台式机构建的Assetbundle不一定适用于webgl。