I have main scene (street) and many child scenes (houses), to which I can come from the main scene. When I come to one home, then go back to the street, I need player object placed near that house, where he was. So I need to use DontDestroyOnLoad
to remember his position.
But when I come at home, I need to disable player object from the main scene and here my code doesn't work. Also after first use of this script in simulation, I can't move cursor up /down, only left/right (and this is first person shooter)
public PS plr;
private GameObject playerOnMainScene;
public void Awake()
{
PlayerSingleton();
DisablePlayerOfMainScene();
}
void PlayerSingleton()
{
if (!plr)
{
DontDestroyOnLoad(gameObject);
plr = this;
}
else
Destroy(gameObject);
}
void DisablePlayerOfMainScene()
{
playerOnMainScene = GameObject.FindGameObjectWithTag("PlayerOnMainScene");
if (SceneManager.GetActiveScene().name != "MainScene")
{
Debug.Log("1"); // this code doesn't work when scene name != "MainScene"
playerOnMainScene.SetActive(false);
}
else
playerOnMainScene.SetActive(true);
}