- Home /
Question by
John Lee · Jan 17, 2013 at 01:27 AM ·
webplayerassetbundle
Why this script load AssetBundle can not work in webplayer?
using UnityEngine;
using System.Collections;
using System.IO;
using System;
using Object=UnityEngine.Object;
public class LoadABs : MonoBehaviour
{
public string path;
// Use this for initialization
IEnumerator Start ()
{
if(Application.platform == RuntimePlatform.WindowsWebPlayer)
{
path = Application.dataPath + "/ABs";
}
else
{
path = Application.dataPath + "/../ABs";
}
System.Random r = new System.Random();
string[] files = Directory.GetFiles(path);
if (files.Length != 0)
{
foreach (string file in files)
{
Debug.Log(file);
WWW www = new WWW("file://" + file);
yield return www;
if (www.isDone)
{
Object obj = www.assetBundle.mainAsset;
GameObject go = (GameObject)Instantiate(obj);
go.transform.position = new Vector3(r.Next(10), 0, r.Next(10));
Debug.Log(go.name);
}
}
}
}
}
I use the script to test, it works good in editor and exe version, however I build to webplayer, it can not work. Why? Web need difference way? Any suggest is very grateful.
Comment
$$anonymous$$ay not be your answer, but I've read somewhere that in a web build, Unity will only load asset bundles from the server where the game is hosted. In addition, I vaguely remember something about permissions. Good luck.
Answer by Graham-Dunnett · Jan 17, 2013 at 11:21 AM
The web player has no access to the file system. When you are running in a web browser all of your asset bundles are fetched from web servers.