Activate Start() on click

I’m making a loading scene. So from the scence B, when I click on the back button, I show a black scence then after loading I have my main menu.

Firstly the progress bar return me always 0. So when I rename my method LoadingScence called when the button is clicked by Sart and everything works fine. But when i want from the menu to go to the scene B, because the script of loading is activated, the Start make me go back to the menu, so I can’t acces to the scene B.

How could I do please ?

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class LevelLoader : MonoBehaviour {

    public GameObject LoadingScene;
    public Image LoadingBar;
    public Text textPourcentage; //The text with the percentage increasing


    public void Start () //When I remane By LoadingScene for example, progress return always 0
    {      
        StartCoroutine (LevelCoroutine ("Main Menu"));
    }

 
    IEnumerator LevelCoroutine (System.String nomScene)
    {
        LoadingScene.SetActive (true);      
        AsyncOperation async = SceneManager.LoadSceneAsync(nomScene);

        while (!async.isDone) {
            LoadingBar.fillAmount = async.progress/0.9f; //Async progress returns always 0 here    
            Debug.Log(async.progress);
            textPourcentage.text = LoadingBar.fillAmount*100 + "%"; //I have always 0% because he fillAmount is always 0
              yield return null;

        }
    }
}

… don’t have line 15 in the code if you don’t want it to load the main menu from this script, or at least surround it with a conditional of some sort, SceneManager has functions to retrieve the current scene etc.

You can’t “avoid” start functions being called. If you don’t want code to run, do put it in / conditional it / put it somewhere else.

Cool, I put a condition in the script and it works fine. But when I reach 90%, the menu start but freeze during 2 seconds, then start normally.

Some people talk about allowSceneActivation but I don’t understand what it means.

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using System;

public class LoadLevel : MonoBehaviour {

    public GameObject LoadingScene;
    public Image LoadingBar;
    public Text textPourcentage; //The text with the percentage increasing
    private String nomScene;
    private Boolean estActive = false;

    public void ChargementScene(String nom)
    {
        nomScene = nom;
        estActive = true;
    }

    void Update()
    {
        if (estActive)
        {
            StartCoroutine(LevelCoroutine(nomScene));

        }
    }

    IEnumerator LevelCoroutine(System.String nomScene)
    {
       
        LoadingScene.SetActive (true);       
        AsyncOperation async = SceneManager.LoadSceneAsync(nomScene);
      

        float val = 0;
        while (!async.isDone && val != 1) {

            LoadingBar.fillAmount = async.progress/0.9f; //Async progress returns always 0 here                      
            textPourcentage.text = LoadingBar.fillAmount*100 + "%"; //I have always 0% because he fillAmount is always 0
            val = async.progress;
           
        

            yield return null;

        }

  

    }
}