- Home /
Question by
bobonik · Jun 19, 2017 at 06:39 PM ·
c#asyncloading screen
LoadSceneAsync with objects retrieved from server
I'm working on a loading screen for my multiplayer game. What I'm trying to do is load a scene asynchronously and while loading it I want to instantiate all the connected users, including me, into the new scene.
I want not only to wait for the new scene to load, but also wait for the new gameobjects retrieved from the server and put them into the new scene.
Here's the code I have in my LevelLoader now:
using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class LevelLoader : MonoBehaviour {
public GameObject loadingScreen;
public Slider slider;
public Text progressText;
void Start()
{
StartCoroutine(LoadAsynchronously());
}
IEnumerator LoadAsynchronously()
{
AsyncOperation operation = SceneManager.LoadSceneAsync(NetworkManager.sceneName);
operation.allowSceneActivation = false;
loadingScreen.SetActive(true);
while (!operation.isDone)
{
float progress = Mathf.Clamp01(operation.progress / 0.9f);
slider.value = progress;
progressText.text = "Loading... " + (progress * 100) + "%";
Debug.Log("Inside Loading...");
yield return null;
}
}
}
Any suggestions?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612124507im_/https://answers.unity.com/themes/thub/images/avi.jpg)