Quantcast
Channel: Questions in topic: "dontdestroyonload"
Viewing all articles
Browse latest Browse all 416

Trouble with DontDestroyOnLoad

$
0
0
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 want to have player object place 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 loading home scene, I can't move cursor un/down, only left/right. 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") // this code doesn't work playerOnMainScene.SetActive(false); else playerOnMainScene.SetActive(true); }

Viewing all articles
Browse latest Browse all 416

Trending Articles