- Home /
How do I make Character Model to change across all scenes if changed in Main Menu?
I am making a 3D game with Multiple levels.
Some levels have different Camera positions & Camera follow scripts.
So, I am not instantiating Character but instead have Character GameObject Prefab in each and every Scenes itself.
In Main Menu I made the option to change characters.
So, how do I make the Characters in the levels change into same as the Selected Character in Main Menu?
Answer by henkehedstrom · Jan 14 at 11:57 AM
If I understand it correctly you want information to get saved between scenes. You choose a certain character in a scene (MainMenu) and then you want every scene to use that character.
To do that you could use a class that stores the character selected and prevent it from being destroyed when you load another scene. You can do that with DontDestroyOnLoad. Now you will have an object that never will get deleted unless you manually choose to do so. The next issue is to access this object, I would use something like a singleton pattern to make it available from anywhere. Then you could acess the character variable in some sort of start function and change it.
@henkehedstrom Thank you for the response. But the thing is some levels have different Camera Transform and Follow scripts attached to Player.
For example, Some levels are top-down view and some side view. Some follows the player and some are fixed. These different Cameras are attached to Player. So I have Camera and Player GameObject Prefabs placed in every levels separately.
So, DontDestroyOnLoad doesn't work for this since Camera Prefabs are different level to level.
I am looking for something that can change Player Prefab within all levels when changed in Menu option.
I don't think that matters. If I understand it correctly you have multiple scripts for different scenarios. You also have different player prefabs that contain these different scripts. In these scripts you have some kind of reference to a character object. In the start function of those scripts you could write something like myCharacter = CharacterManager.Instance.GetPreferredCharacter();
Where myCharacter is the variable that you are using in the scripts and CharacterManager is the class that is dontdestroy on load. Instance is part of the singleton pattern, you could access the CharacterManager in other ways aswell. And lastly the GetPreferredCharacter() is a function you create that returns the character that the user selected in the main menu.
If you share some of the code I could help you to implement the changes.
Your answer
Follow this Question
Related Questions
How to Make animation Playable? 1 Answer
How to change character weight in Unity? 2 Answers
Why isn't AddTorque working on this character? 0 Answers
Saving character selection 1 Answer