- Home /
Loading a level. (Few questions)
I made a cave into my game and put a teleport trigger to get inside the cave. I realized that, if I want the game to work properly without lagg, I need to make a new scene for the cave.
When i load use Application.Loadlevel("Cave01");
1. If my character has for example 70/100 health and some equipment equipped + stuff in his inventory. How do i transfer all that stuff to the cave scene.
2. Same thing but with eg movement scripts. Can I somehow put the character related stuff to be "global" so that it saves between scenes?
Haven't actually made the inventory scripts or health scripts yet, but I would like to know this stuff in advance, before moving forward. Thanx for the help!
Answer by Seth-Bergman · Oct 24, 2012 at 09:34 PM
1: OK, basically you can use DontDestroyOnLoad to keep your player's stats intact
2: Global may not be quite what you want, that refers to SCOPE, but what you are reaching for is STATIC.. You can make vars static (global) to keep them from resetting, but.. Be AWARE, making your data members static means there is only one instance of that var across all scripts, so it retains it's value from one script instance to another, but in the case of a player status script, that's what you want anyway..
for example:
var score : int; // resets on load
static var score : int; // will retain its value between scenes (one value across all instances)
By the way, please don't post responses to answers as new answers, you can use the comment field for that.. And if an answer helps you, mark it as accepted! (the check mark) And Welcome to the forum!
Ah, okay thanx. That helped a lot. Where is the accept button? Can't seem to find it. nvm found it.
Your answer
Follow this Question
Related Questions
Application load advanced loading NO EXPERIENCE 2 Answers
Loading a level on contact 2 Answers
Load Level when Key is pressed 2 Answers
level loader script wont work 1 Answer