Switching scences without loosing players position

Hey guys!

I’m working on my first game in Unity and I have a big problem.

There are 2 worlds in this game and in each world there are 5 houses you can walk in. So my big problem is, how can i make a script, in which the postition of my player is saved? Every time when I leave the houses I start at the beginning and I have already tried it with DontDestroyOnThis and saving the players position, as explained here in the forum, but nothing worked.

I don’t know if i have to make a new script with dontdestroyonthis and connect it to the Player or do i have to put the code inside of the “FristPersonController” script. By the way I’m using the Unity Standard Asset First Person Controller.

Please can someone tell me the easiest way to manage this. The level switches are made with function OnTriggerEnter () and Application.LoadLevel (). Maybe I can write something in the triggers to realize that? Please help me I’m in a hurry and thanks a lot.

There´s a function called DontDestroyOnLoad or similar. This should do the trick.

see http://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html

Guess they didn’t read that you’d tried that! :smiley:

OK DontDestroyOnLoad is what you need BUT it’s not the complete solution, for that you have to record the scene just before you load the next one. So put a variable in DDOL that will still know what the last scene was.

Then when the next scene loads you check what scene you came from. I just had a list of empty gameObjects and when I changed scenes I move the player instantly to the right position/rotation depending on the previous scene.

EDIT should have said really - you need Application.loadedLevelName to record the scene name just before you load the next one. Store that in Don’t destroy and then pick the correct location for your player using if or case depending on how many you have.