Why does my game forget which shape my player has when loading a new room?
So here's the deal: I have a game and in it you are playing as a cube and you can travel between rooms and once you enter a trigger, it will load a new scene(room) and your position will be set and DontDestroyOnLoad is called for the player object so that things that you have done to your player should not be destroyed, like color, since there is a cheat for changing color, and shape, since you can enter a cheat and become a ball instead of a cube.
Now, the problem is if you enter the cheat to become a ball, and you enter a new room, the cube-model gets enabled again for some reason even though it shouldn't.
Why is this happening? Could there be a problem with my cheat script?
LoadLevel-Script: https://justpaste.it/u69r
Cheats-script: https://justpaste.it/u69t
Answer by M-Hanssen · May 11, 2016 at 12:50 PM
instead of doing this:
DontDestroyOnLoad(GameObject.Find("PLAYER"));
player = GameObject.Find("PLAYER").gameObject;
Try doing this:
player = GameObject.Find("PLAYER").gameObject;
DontDestroyOnLoad(player);
Remember that finding a player by tag is bad practice. if you have a player script attached to the player try to find the player by type by using FindObjectOfType(), or even better build a player manager that keeps track of the player(s)
What do you do @ the line player.GetComponent<Player>().Spawn();
?
You intent to keep this player because you set DontDestroyOnLoad, so why do you spawn a new player when the loading of the level is done?
player.GetComponent().Spawn(); is a function in the player-script that is supposed to set the position of the player when a new room is loaded but it doesn't work the way I want and so I forgot to remove it, it does not serve any function at the moment.
Your answer
Follow this Question
Related Questions
Reset PlayerPrefs on Build? 2 Answers
I want to import CFD data. 1 Answer
Application.LoadLevel crashes unity 0 Answers
Variables changes even on pause 0 Answers