Hello,
I have made a little loading screen using the unity UI but right now running it stops my other functions that I want to run in the background, E.G. my CreateRoom Function should run alongside the loading screen.
my code is:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class GenerateDungeon : MonoBehaviour {
//Chosen Prefabs
public Transform WallPrefab;
public Transform GroundPrefab;
public int MaxRoomX;
public int MaxRoomZ;
public Canvas LoadingCanvas;
public Text LoadingDots;
private bool CreateWall;
private bool WallX;
// Use this for initialization
void Start () {
LoadingCanvas = LoadingCanvas.GetComponent<Canvas> ();
LoadingDots = LoadingDots.GetComponent<Text> ();
CreateRoom ();
}
// Update is called once per frame
void Update () {
}
void CreateRoom() {
//Test Room
int RoomWidth = MaxRoomX;
int RoomLength = MaxRoomZ;
Debug.Log ("Starting Load");
StartCoroutine (LoadingScreen (true));
for (float Width = 0; Width < RoomLength; Width++) {
for (float Length = 0; Length < RoomWidth; Length++) {
float X = 2.5f * Length;
float Z = 2.5f * Width;
Instantiate(GroundPrefab, new Vector3(X, 0, Z), Quaternion.identity);
//Debug.Log ("Creating Ground");
}
}
//LoadingScreen (false);
}
IEnumerator LoadingScreen(bool Run) {
int i = 0;
Debug.Log ("Starting Loading Screen");
int DotNum = 4;
while (Run == true) {
Debug.Log ("Run Is True");
if (i == DotNum) {
LoadingDots.text = "";
Debug.Log ("Reseting Dots");
i = 0;
}
for (i = i; i < DotNum; i++) {
Debug.Log (i.ToString());
LoadingDots.text += ".";
Debug.Log (LoadingDots.text);
yield return new WaitForSeconds(0.5f);
}
}
}
}
I want the LoadingScreen and CreateRoom to run together, I have tried CoRoutine but that stops the other function.