Hi!
I’m working on a mobile game, which has a level selection. I have a GameManager singleton instance in the first(Main menu) scene, I put it in the DoNotDestroyOnLoad. Have a list of scene objects in it, which I set in the editor. On start, I take the list of scenes, and get the names, creating as many buttons for level selections as many scenes I have in the list. And when I click on the button, just read it’s property, which is the scene’s name, and load it. It’s perfectly working in editor, even in unity remote with phone, but when I build the project, install it on my android phone, There is no level button(so it didn’t find the scenes in the list), and when I somehow manage to add one, it won’t load the scene.
Does anyone have any idea, what’s the problem?
GameManager:
void Awake()
{
if (_GameManager != null && _GameManager != this)
{
Destroy(this);
} else
{
_GameManager = this;
DontDestroyOnLoad(this);
}
List<string> tempList = new List<string>();
foreach (Object scene in sceneObjects)
{
tempList.Add(scene.name);
}
levels = tempList.ToArray();
}
SceneManager:
void Start()
{
for (int i = 0; i < GameManager._GameManager.levels.Length; i++)
{
GameObject newStage = Instantiate(stageReference, new Vector3(0, 0, 0), Quaternion.identity, parentReference.transform);
newStage.GetComponent<Level>().SetLevelNumber(i+1);
newStage.GetComponent<Level>().SetSceneName(GameManager._GameManager.levels[i]);
}
}
LevelObject:
public void HandleClickedOnLevel()
{
if (unlocked)
{
SceneManager.LoadScene(sceneName);
}
}