- Home /
The question is answered, right answer was accepted
Trouble With Loading Bar Script C# Unity 5
I was following this tutorial on how to make a loading screen on YouTube. I have followed his script exactly but I am getting all sorts of errors and I can't figure out why. YouTube Tutorial
using UnityEngine;
using System.Collections;
public class LoadingScreen : MonoBehaviour {
public string levelToLoad;
public GameObject background;
public GameObject progressBar;
public GameObject text;
private int loadProgress = 0;
// Use this for initialization
void Start () {
background.SetActive (false);
progressBar.SetActive (false);
text.SetActive (false);
}
public void GoMusicPlayer02(){
StartCoroutine(DisplayLoadingScreen(levelToLoad));
}
// Update is called once per frame
void Update () {
IEnumerator DisplayLoadingScreen(string level){
background.SetActive (true);
progressBar.SetActive (true);
text.SetActive (true);
progressBar.transform.localScale = new Vector3(loadProgress, progressBar.transform.localScale.y, progressBar.transform.z);
text.GetComponent<GUIText>().text = "Loading Progress " + loadProgress + "%";
AsyncOperation async = Application.LoadLevelAsync(level);
while(!async.isDone){
loadProgress = (int)(async.progress * 100);
text.GetComponent<GUIText>().text = "Loading Progress " + loadProgress + "%";
progressBar.transform.localScale = new Vector3(async.progress, progressBar.transform.localScale.y, progressBar.transform.z);
yield return null;
}
}
}
}
I forgot to include the error messages I am getting:
Assets/Scripts/LoadingScreen.cs(50,1): error CS8025: Parsing error
Assets/Scripts/LoadingScreen.cs(27,49): error CS1525: Unexpected symbol (', expecting )', ,', ;', [', or ='
Answer by m4c0 · Mar 13, 2015 at 02:36 AM
Your IEnumerator DisplayLoadingScreen(string level) is inside void Update(). You can't have a method inside another method.
Thanks m4c0, Yup that was it, plus the other classic screwup of not having the localScale in front of the z The script works but not as I expected. $$anonymous$$y level that loads still freezes while all of the songs from the array list get loaded in. I thought the whole purpose of the load screen was to prevent that?? Oh well that is another question I suppose ;)
I can't find in docs, but the guy from the video says it needs Pro license. Could that be it?
Yes, unity pro is required but my understanding is that if you have unity 5 you have all of the pro features so that should not matter... unless I'm missing something there?