我在为webgl做一个游戏。但是,当我在链接上上传资源包,然后将其加载到游戏中时,它显示错误。
错误:无法解压缩AssetBundle 'Memory‘的数据。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);
}“”“
发布于 2019-10-03 16:05:33
您确定您在构建资产包时也考虑到了正确的平台吗?为桌面构建的Assetbundle不一定适用于webgl。
https://stackoverflow.com/questions/58213726
复制相似问题