How Do I access This Load Coroutine From Here?

I need to access This:

public void LoadGameLevel(int sceneIndex)
    {
        StartCoroutine(LoadAsychronously(sceneIndex));

    }

    IEnumerator LoadAsychronously(int sceneIndex)
    {
        AsyncOperation operation = SceneManager.LoadSceneAsync(sceneIndex);

        loadingScreen.SetActive(true);

        while (!operation.isDone)
        {
            float progress = Mathf.Clamp01(operation.progress / .9f);

            slider.value = progress;
            progressText.text = progress * 100f + "%";

            yield return null;
        }
    }

From This:

void OnTriggerEnter(Collider other)
    {
        if (Is_OK_To_Exit == true && other.gameObject.tag == "Player")
        {
            Debug.Log("Access Granted");
            // For Now As A Simple Test We'll Just Reload Level 1
           
        }
        else if (Is_OK_To_Exit == false && other.gameObject.tag == "Player")
        {
            Debug.Log("Access Denied");
        }
    }

I can do It from a button but I need to do it as a player enter into a trigger collider.

Call it like you would call any other method in a different script: get a reference to that script and call the method by the reference. If that script is attached to the gameObject entering the trigger, you can use
other.gameObject.GetComponent<YourScriptName> ().LoadGameLevel (1);

Otherwise, you need to refernce the corresponding gameObject in a different way (e.g. a public field, via singleton reference, GameObject.Find (), or something along those lines).

Yes but I need to access this:

public void LoadGameLevel(int sceneIndex)

so that it runs the coroutine? Both of those are on the same script, not separate ones, I’m just using a collider instead of a button. Sorry Have never been much good at level loading stuff :confused:

EDIT:
Never mind, I think if I’m understanding you correctly all I need in that same script is this in order to access the coroutine:

LoadGameLevel (1);

Yeah, I already got that, that’s why I tried to help you access LoadGameLevel. :wink:
Is your OnTriggerEnter in the same script as your LoadGameLevel? If so, you can just call it inside the OnTriggerEnter. If not, where in your hierarchy is it?

Thanks, the LoadLevel script is on a game object that has a tunnel with a box collider inside of it.

Alright, so it’s not involved in the collision that’s happening, right? Because then we need to get the reference in a different way, but that’s not a problem. Did you consider making the LoadLevel script a Singleton? If not, I suggest you do a quick research about those and give it a go. Should be pretty easy to do and if you get stuck, I’ll help you out.

1 Like