- Home /
Question by
Jom000 · Jul 30, 2016 at 10:24 AM ·
assetbundleplatform
AssetBundle LoadAsset questions in android
Hi everyone,I use LoadAsset Functions to load my asset "sysm.jpg",in unity editor work find,but it can't work in android.this is my building AssetBundle code.
BuildPipeline.BuildAssetBundles ("Assets/AssetBundles", BuildAssetBundleOptions.None,BuildTarget.Android);
and this is my C# code.
IEnumerator DownloadANdCache (){
while (!Caching.ready)
yield return null;
Debug.Log (BundleURL);
using (www = WWW.LoadFromCacheOrDownload (BundleURL, version)) {
while (!www.isDone) {
Debug.Log(www.progress);
float jdt = www.progress*100;
loading_Text.GetComponent<UnityEngine.UI.Text> ().text = (jdt.ToString("f1") + "%");
loading_Jdt.GetComponent<UnityEngine.UI.Image>().fillAmount = www.progress;
yield return null;
}
//yield return www;
if (www.error != null) { //some error
throw new Exception ("error:" + www.error);
Application.Quit ();
}
AssetBundle bundle = www.assetBundle;
UnityEngine.Texture2D temp_cx = (bundle.LoadAsset ("sysm.jpg")) as UnityEngine.Texture2D;
L_Obj [0].GetComponent<UnityEngine.UI.Image> ().sprite = Sprite.Create(temp_cx,new Rect(0,0,temp_cx.width,temp_cx.height),new Vector2(0.5f,0.5f));
}
}
My English is not so good,i hope say it clearly. Thank you very much.
Comment
Best Answer
Answer by Jom000 · Aug 01, 2016 at 02:19 PM
All right, I found the way to solve the problem.
BuildPipeline.BuildAssetBundles ("Assets/AssetBundles", BuildAssetBundleOptions.None,BuildTarget.Android);
change to
BuildPipeline.BuildAssetBundles ("Assets/AssetBundles", BuildAssetBundleOptions.CompleteAssets,BuildTarget.Android);
Your answer
![](https://koobas.hobune.stream/wayback/20220612085831im_/https://answers.unity.com/themes/thub/images/avi.jpg)