Complete Unity novice here. First project ever, trying to get familiar and understand the basic aspects of game development with Unity. Trying to work with scenes now.
I have two scenes in my Hierarchy view. I added both to the Build Settings.
The MainScene
contains the player sprite and the main game elements, while the TitleScene
contains the game name text and a progress bar.
I set TitleScene
as the active scene using the option Set Active Scene in the ellipsis context menu of the scene element in the Hierarchy view.
I want to show only one scene on game start, the TitleScene
.
The TitleSceneLogic.cs script is attached to a game object in the TitleScene
public class TitleSceneLogic : MonoBehaviour
{
void Start()
{
print("Title Scene started");
}
}
The MainSceneLogic.cs script is attached to a game object in the MainScene
public class MainSceneLogic : MonoBehaviour
{
void Start()
{
print("Main Scene started");
}
}
Every time I hit Play to see the game running:
- Both scenes are being shown (overlapping)
- Console panel shows both Main Scene started and Title Scene started.
Is this really the default behavior in Unity, to load all scenes when the game starts?
I need to show one scene only on game start, the TitleScene
.
I gave it a shot by adding this to the MainSceneLogic.cs's Start
function
SceneManager.LoadScene("TitleScene");
and indeed only the title scene is shown now, but:
- I have the feeling this is not the right way, do I really have to manually load a specific scene in the code when the game starts?
- The logs:
- Title Scene started
- Main Scene Started
- Title Scene started
What is the right way to load only one scene on game start?