In the Hierarchy in the editor I have two scenes. And I have in Menu scene I have a button called: StartGameButton
When I click the button while the game is running in the editor it’s working. I click on the button and it’s turning on enabled true the player2 in the The Space Station scene.
But after building the game and running the game exe when I click the button it does nothing.
This is a screenshot of the two scenes in the Hierarchy and the button Inspector:
You can see in the screenshot that player2 is in gray enabled false off. In the button I have attached the script LoadSceneOnClick:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class LoadSceneOnClick : MonoBehaviour
{
public void ActivatePlayer()
{
GameControl.player.SetActive(true);
SceneManager.UnloadSceneAsync(0);
}
}
I created a static class to be able to use a variable between the two scenes:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public static class GameControl
{
public static GameObject player;
}
Then in the scene The Space Station I have a gameobject with this script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerControl : MonoBehaviour
{
public GameObject player;
// Use this for initialization
void Start ()
{
GameControl.player = player;
}
// Update is called once per frame
void Update () {
}
}
So when I click the button StartGameButton it’s first changing the player2 to be enabled true and then unloading removing the Menu scene.
GameControl.player.SetActive(true);
SceneManager.UnloadSceneAsync(0);
This is working fine in the editor. But it’s not working in the build after building the game and running the exe file I see the Menu scene and the buttons but it does nothing when I click on the button.
And I see that in the build when running the game the whole game looks not the same like in the editor.
This is how the game looks like in the editor:
Since the active scene is the The Space Station and player2 is off the game start with the main menu but with the skybox and other objects of the The Space Station scene.
Then I click on the button START GAME: And it’s taking me to the The Space Station scene:
And remove unloaded the Menu scene:
But when I’m running the build exe file it looks like this:
Not even close to what it looks like in the editor.
This is a screenshot of the Build Settings… window: I can’t figure out why it’s working fine in the editor but not when running the exe built file.
Did I do something wrong with the Build Settings ?