Quantcast
Channel: Questions in topic: "assetbundle.loadasync"
Viewing all articles
Browse latest Browse all 39

Changing Scenes using Unity5 AssetBundle

$
0
0
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](https://www.assetstore.unity3d.com/en/#!/content/45836) to build my AssetBundles. Ok, heres what i'm trying to achieve: 1. Game starts at Scene1. 2. Load Scene2 from asset bundle and change scene to Scene2. 3. 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!

Viewing all articles
Browse latest Browse all 39

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>