Hello, does anyone know how to split the prefabs we get when we load in an assetbundle? When I get the prefabs I'm giving them a script but I wanted them to stay in a single gameobject for each to have their position and so on. I have to do this all by code because I am trying to do something automatic.
void Start () {
StartCoroutine("DownloadObject");
}
IEnumerator DownloadObject()
{
Caching.CleanCache();
WWW www = WWW.LoadFromCacheOrDownload("file:///" + Application.dataPath + "/AssetBundles/bottle", 1);
yield return www;
AssetBundle bundle = www.assetBundle;
AssetBundleRequest requestObjects = bundle.LoadAllAssetsAsync();
yield return requestObjects;
for (int i = 0; i < requestObjects.allAssets.Length; i++)
{
GameObject bottles = requestObjects.allAssets[i] as GameObject;
bottles.gameObject.AddComponent();
Instantiate(bottles);
}
}
↧