How do I call a function from an additive scene in Unity?
I'm (attempting) to make a a loading screen for my game. The tutorial I'm using is one from GameDevGuide on Youtube:
https://www.youtube.com/watch?v=iXWFTgFNRdM
I have no problem understanding the method of persistent additive scene loading, however, I am thoroughly confused as to how the 'Play' button was able to invoke the LoadGame()
function.
This is because the play button is in the 'Title Screen' scene whereas the GameManager
script (with the LoadGame()
function) is in the Persistent Scene (in which the Title Scene is loaded into additively).
My StartGame()
(Meant to be called by a button from an additive scene) and Start()
functions:
public void Start()
{
loadingScreen.SetActive(false);
//SceneIndex is a reference to an enum class
SceneManager.LoadSceneAsync((int)SceneIndexes.TITLE, LoadSceneMode.Additive);
}
List<AsyncOperation> scenesLoading = new List<AsyncOperation>();
public void StartGame()
{
loadingScreen.SetActive(true);
scenesLoading.Add(SceneManager.UnloadSceneAsync((int)SceneIndexes.TITLE));
scenesLoading.Add(SceneManager.LoadSceneAsync((int)SceneIndexes.LEVEL, LoadSceneMode.Additive));
}
I've tried using Prefabs with the GameManager
script attached to it, but the Loading Screen GameObject was unable to be assigned (And it's going against the entire point of having a persistent scene). I'm quite certain there's nothing wrong with my loading code, it's just how I set it up in Unity (or I'm missing some scripts).
Thanks so much in advance for any help. I'm relatively new at Unity and maybe I missed something in GameDevGuide's tutorial.