How to mantain informations between scene transiti

2019-08-30 05:05发布

I am working on temple run like game using this Kit. https://www.assetstore.unity3d.com/#/content/3292. I want to insert a room with two doors , when my player enters in the room it stops running and user can control with arrow keys , and when it leaves the room by back door it starts running again . what should i do when it collides with the door collides ? I am doing this by replacing the scenes. I am instantiating an empty Game-object prefab in GamePlayScene when player is colliding with that i am loading HouseScene and when it is colliding with back door (in HouseScene) i am loading GamePlayScene. but the game is starting from the beginning. how can I resume the game From where I left And keep the track of Distance covered and coins collected? And also for HouseScene . Remember the points i achieved in it. Thanks.

标签: unity3d
1条回答
虎瘦雄心在
2楼-- · 2019-08-30 05:40

You need to save the informations that you want to keep between your scenes. You have some possibilities about that:

1) Save your informations in a text file and retrieve those when you load a new scene (but this way is a bit "dirty" and not recommended...the next points of this list are better solutions);

2) Using PlayerPrefs. They provide getters and setters to retrieve/store data in/from the registry of your operative system.

3) Using an object (as a container) that contains all your "global" variables (the ones that you want to mantain between scenes' transition), and invoking the DontDestroyOnLoad function on it. That way, your "container" (with its data) will persist in the entire life cycle of the game.

查看更多
登录 后发表回答