- Home /
Changing Scenes using Unity5 AssetBundle
Hiya, I'm new here and I'm using Unity version 5.2.03f and I'm new to asset bundle. I'm using AssetBundleManager to build my AssetBundles.
Ok, heres what i'm trying to achieve:
Game starts at Scene1.
Load Scene2 from asset bundle and change scene to Scene2.
Load Scene3 from asset bundle and change scene to Scene3.
This code is included in a GameObject at the start to initialise the AssetBundleManager:
protected IEnumerator Initialize()
{
DontDestroyOnLoad(gameObject);
#if DEVELOPMENT_BUILD || UNITY_EDITOR
AssetBundleManager.SetDevelopmentAssetBundleServer ();
#else
AssetBundleManager.SetSourceAssetBundleURL(Application.dataPath + "/");
#endif
var request = AssetBundleManager.Initialize();
if (request != null)
yield return StartCoroutine(request);
}
And this script is in a Loading game object that won't be destroyed and stayed throughout the game, Loading.cs:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using AssetBundles;
public class Loading : MonoBehaviour {
public string sceneAssetBundle;
AssetBundleLoadOperation request;
public void LoadScene(string level){
StartCoroutine (LoadingScreen(level));
}
IEnumerator LoadingScreen(string level){
request = AssetBundleManager.LoadLevelAsync (sceneAssetBundle, level, true);
if (request == null)
yield break;
}
}
By using the function LoadScene from Loading.cs, I can load the scenes with no error. But the scenes keep overlapping one after another. and Application.loadedLevelName
is always Scene1.
My Question is, how do i delete the previous scene when i opened a new scene OR how do i use Application.LoadLevel()
with the new AssetBundle. Thanks!
i am trying to do something like that but i think it is impossible, i tried to save scenes from WWW to local storage and replace them with main scenes but i couldn't do that. may be we should let the user choice between current scene and the DLC ...