Hello, I’m a begginer in Unity and I’d like to learn how to change a scene and how to keep my character’s data in all scenes(like life remaining, etc.). I also would like to do a menu in the same way. I think it is a matter of design, and I would like to learn how to design it. Thank you and sorry about my english
You’d just pop a DontDestroyOnLoad onto whatever you’d like to maintain.
http://unity3d.com/support/documentation/ScriptReference/Object.DontDestroyOnLoad.html
The easiest way is probably to use DontDestroyOnLoad()
. I would create a scene manager that is responsible for loading levels and managing player health and inventory and other similar things. Then tell Unity not to destroy it when the level changes.
//SomeOtherScript.js
static var gameManager : YourPlayerManager;
function Start () {
gameManager = FindObjectOfType(YourPlayerManager) as YourPlayerManager;
DontDestroyOnLoad(gameManager.gameObject);
}
//Now that object will not be destroyed when you load a new level and you can
//access it using SomeOtherScript.gameManager.