Loading screen C#

Hi there!

I’m trying to make a loading system where I load a loading scene first and then I load the new scene asyncrounosly with it’s loading bar and stuff.

My script is this one:

public string Scene, loadingScene;
    Scene sScene;
    AsyncOperation asyn;

    void Start ()
    {
        DontDestroyOnLoad (this);
    }
   
    void Update ()
    {
        sScene = SceneManager.GetActiveScene ();

        if (sScene.name == loadingScene)
        {
            LoadScene (Scene);
        }
    }

    public void LoadLoadingScene()
    {
        SceneManager.LoadScene (loadingScene);
    }

    public void LoadScene(string ss)
    {
        SceneManager.LoadSceneAsync (ss);
        Slider s = GameObject.Find ("BarraCarga").GetComponent<Slider> ();
        s.value = asyn.progress;
    }

    public void ChangeString (string s)
    {
        Scene = s;
    }

I put the function to load my scene on update, to check when I’m on my loading scene, but the issue is that in update I call this funcion like a hundred of times, and I want to know how call it just once o another way to do this.

Thanks you all :slight_smile: sorry for my bad english xD

I’d suggest that you begin here: Learn

Have you gone through a number of early tutorials and created and/or modified some small projects, already?

It always sucks to say but this is fairly basic.

You have an AsyncOperation but never assign anything to it and your method being called every frame for example are classic examples.

I am not sure how I can help you without just redirecting you to a different tutorial.

Here, watch this:

1 Like