Move my entire player gameobject in the next scene (using loadlevel)

Hey all,

I’m working on a platformer and I have one scene which is supposed to be like open world and a small building with a door that’s supposed to be a shop building. I’d like when player gets to the door and press UP to be able to spawn in the new scene called house.unity. I tried several ways and read around dozen of websites/answers to the similar issue but couldn’t find a complete answer :confused:

There are two main issues: a) I want to keep the player, for example even tho player starts first as a prefab, once the user is playing the game, player is supposed to gather weapons and those show up on the character as well… Simply instantiating a basic player prefab in a store is a big no-no… + I want to keep player’s score, money, attributes etc…

b) I want to keep track of x/y coordinates of door entrance, so when I later want to exit the shop I’ll be spawned just outside it…

Now I read A LOT about PlayerPrefs, DontDestroyOnLoad, OnLevelWasLoaded or even using a static variables but still find it hard to find the best or working way :confused:

So the scenario is:
-Player is spawned into a world at a start of a new game by simply instantiating player prefab at designated spot.

-Camera isn’t father/child of player, it’s another GameObject floating in hierarchy that follows player via code.

I have a world and a door. Door has a trigger and is supposed to enable loading of level “house_01.unity”.

The “house_01.unity” contains scene with merchant and a door. Does this scene needs another camera? a spawn point?

How can I TAKE my player, totally cut and paste it at “house_01.unity” at lets say empty gameobject with name “spawnMeHere” and also move a camera into that scene as well?

It might looks like I’m lazy and I want YOU to do the work instead of me, but I spent a good 3-4hrs just looking for solution and I’m not getting it :frowning:

Thanks all

You can transfer data between scenes by writing data to a static variable. You could have one class that stores all your transferable information.

public static class GameSettings{

 public static Character save;

}

You can write to this by having a line whenever you change scenes like “GameSettings.save = characterStats”

or something like that. use as many variables as you need or save the whole class. However, this wont save when you shut down your game. You need to use player preferences for something like that.

Also, to spawn your character at a certain location, have a script that moves the character when the scene loads. You can have an empty gameobject on the location you want him to appear. The script could say something like “player.transform.location = GameObject.FindObjectWithTag(“spawnLocation”).transform.location;” Where spawnLocation is the tag on your empty gameobject denoting your spawn point.

Additional info, each of your scenes does need its own camera and spawn point unless you have it attached to the player prefab as part of the prefab