I made a scene where all the levels of the game are displayed, for this I made a script where I create a list of all the scenes (levels) that are filled through the inspector ( https://prnt.sc/n96sy0 ).

Each element of the list is a prefab, a button with text, the text is the name of the scene. Uses standard Scroll View ( https://unity3d.com/ru/learn/tutorials/topics/user-interface-ui/scroll-view ).

The problem is that the android does not display a list of levels, although the editor itself has all the rules. On the 1st screen, running scene.

Through Unity Remote all the rules.

Here is a screen from the phone, it displays only 1 default prefab - https://prnt.sc/n96x7k

The code that runs when the scene loads:

public class ListScenes : MonoBehaviour { public GameObject viewLevel; //Префаб, который отображается в content public List<Object> scenes; //Список сцен private GameObject content; //Объект, в который будут добавляться префабы void Start() { content = Helper.FindInChildren(gameObject, "Content"); addScenesToList(); } private void addScenesToList() { foreach (Object scene in scenes) { GameObject obj = Instantiate(viewLevel, content.transform); //Создаю префаб и кидаю его в content Helper.FindInChildren(obj, "Text").GetComponent<Text>().text = scene.name; //Ищу в своем префабе компонент Text и меняю текст на название сцені obj.GetComponent<Button>().onClick.AddListener(() => { SceneManager.LoadScene(scene.name, LoadSceneMode.Single); }); //Вешаю свой обработчик нажатия } } } 

The latest version of Unity.

Or maybe someone has other ideas, how to display a list of levels?

Help me please)

  • And when building apk, these scenes are added in the "Build Settings" window? - Alexander Danilovsky
  • @ Alexander Danilovsky of course ( prntscr.com/n98052 ) - By Arper

1 answer 1

Without the direct appointment of scenes there is such a way. In your case, instead of int i = 0, you should specify the index of the first scene.

 int count = SceneManager.sceneCount; for (int i = 0; i < count; i++) { var scene = SceneManager.GetSceneAt(count); //Ваша логика работы со сценами } 

Put the debugs inside your code and look in the phone console when you start the game, or connect to the phone through your code editor and put a break point at the spawn point of the buttons - to understand what is wrong there.

Another common problem "In the editor, all the rules, but on the device - no," is the unpredictability of the execution of the Start and Awake methods. Those. for example, you have two classes, one of which in Start writes itself somewhere, and the second in its Start receives the first of the place where it is enrolled.

In the editor, such code can easily work, but on the device an error will fall due to the fact that the order of calling Start-s changes. In any case, you must first watch the application console on the phone.