- Home /
how do i make a script that records where a player was before entering another room
For instance, if I'm currently on the world scene and I am in the village "Some Village" I go near a house door and enter the house scene. I can walk around a bit and explore the scene and, once I get out the house scene the player should be outside the house he was just in and not some other place, my question is what script can I use to accomplish this?
Check my answer here : http://answers.unity3d.com/questions/237485/change-position-of-camera-on-scene-load.html
And deploy the singleton method in the comments. Let me know if this is confusing =]
the basic principle is (1) use PlayerPrefs; or (2) use a singleton with DontDestroyOnLoad.
more on singleton : http://answers.unity3d.com/questions/11314/audio-or-music-to-continue-playing-between-scene-c.html
http://wiki.unity3d.com/index.php?title=Singleton : http://www.dotnetperls.com/singleton-static
To keep it simple, this is one way you could do it... function BeforeEntering() { playerPrefs.SetFloat("pposx", transform.position.x); playerPrefs.SetFloat("pposy", transform.position.y); playerPrefs.SetFloat("pposy", transform.position.z); }
function AfterExitting() { transform.position.x = playerPrefs.GetFloat("pposx"); transform.position.y = playerPrefs.GetFloat("pposy"); transform.position.z = playerPrefs.GetFloat("pposz"); }
Thanks man! That worked :), It was easier to understand this explanation than the others :D