0
0
Unityframework~10 mins

Build settings and scene order in Unity - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to load the first scene in the build settings by its index.

Unity
SceneManager.LoadScene([1]);
Drag options to blanks, or click blank then click option'
A0
B1
C"MainScene"
DSceneManager.GetActiveScene()
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of 0 for the first scene index.
Trying to load scene by name without quotes.
Using the active scene instead of the build index.
2fill in blank
medium

Complete the code to add a scene named "Level2" to the build settings scenes list.

Unity
EditorBuildSettingsScene newScene = new EditorBuildSettingsScene("Assets/Scenes/[1].unity", true);
Drag options to blanks, or click blank then click option'
ALevel1
BMainMenu
CLevel2
DGameOver
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong scene name that does not exist.
Forgetting the folder path "Assets/Scenes/".
Not including the .unity extension in the path.
3fill in blank
hard

Fix the error in the code to correctly get the total number of scenes in build settings.

Unity
int sceneCount = [1].Length;
Drag options to blanks, or click blank then click option'
ASceneManager.GetAllScenes()
BEditorBuildSettings.scenes
CBuildSettings.scenes
DSceneManager.sceneCountInBuildSettings
Attempts:
3 left
💡 Hint
Common Mistakes
Using EditorBuildSettings.scenes which is editor-only.
Trying to call a method that does not exist.
Using incorrect property names.
4fill in blank
hard

Fill both blanks to check if the current active scene is the last in build settings.

Unity
bool isLastScene = SceneManager.GetActiveScene().buildIndex [1] SceneManager.sceneCountInBuildSettings [2] 1;
Drag options to blanks, or click blank then click option'
A==
B-
C+
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using + instead of - when adjusting scene count.
Using != instead of == for comparison.
Mixing up the order of operands.
5fill in blank
hard

Fill all three blanks to create a dictionary mapping scene names to their build indexes for all scenes in build settings.

Unity
var sceneDict = new Dictionary<string, int>() {
  { [1], [2] }
};
for (int i = 1; i < SceneManager.sceneCountInBuildSettings; i++) {
  sceneDict.Add(SceneUtility.GetScenePathByBuildIndex(i).Split('/').Last().Replace(".unity", ""), i);
}
Drag options to blanks, or click blank then click option'
ASceneUtility.GetScenePathByBuildIndex(0).Split('/').Last().Replace(".unity", "")
B0
CSceneUtility.GetBuildIndexByScenePath("Assets/Scenes/Main.unity")
D"Main"
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong index or scene name for the first dictionary entry.
Not removing the .unity extension from scene names.
Using SceneUtility.GetBuildIndexByScenePath incorrectly.