Question by
Formigaz · May 05, 2017 at 10:54 AM ·
gameobjectinstantiateassetbundleassetbundles
[Asset Bundle] Split the prefabs into a single gameobject
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<GameObject>();
yield return requestObjects;
for (int i = 0; i < requestObjects.allAssets.Length; i++)
{
GameObject bottles = requestObjects.allAssets[i] as GameObject;
bottles.gameObject.AddComponent<BottleScript>();
Instantiate(bottles);
}
}
Comment
Your answer
Follow this Question
Related Questions
Instantiating GameObject and Adding to list 3 Answers
Destroy Instantiate is not working 0 Answers
ExecuteInEditMode is not working when trying to instantiate a new GameObject [SOLVED] 1 Answer
Error loading assetbundles on ios in background,Error loading assetbundles on ios in background 0 Answers
How to find the (original) Prefab of a GameObject? 2 Answers