|
Hello. I have a simple question. I am making a game and I will thet if the player restart the game, it should be able to load the last scene/level with a button, where he played last time. Is this possible? And how? A script will be good;).
(comments are locked)
|
|
no one of this scripts are working:( is there anyone with a working script or description? All these answers people posted should have been plenty of help to get you going.
Jan 06 '12 at 09:05 PM
Lo0NuhtiK
But it will be easyer if anyone post me a good code
Jan 07 '12 at 08:10 AM
worldofcars
....uh-huh.
Jan 07 '12 at 08:16 AM
Lo0NuhtiK
(comments are locked)
|
|
You need to store a piece of information in some way, You can do this by using PlayerPrefs this wil save a specific piece of information to the disk. and you can load this when ever you want: for example the player ends in level 10 and the name of the scene is level10 you can use this to save it: PlayerPrefs.SetString("lastlevel", "level10"; and you can call this info by using: PlayerPrefs.GetString("lastlevel") and to put it into context... var lastlevel = PlayerPrefs.GetString("lastlevel"); Application.LoadLevel (lastlevel); before the player starts in this level you already need to save this in advance (what if the player would quit the game abruptly, then this data would also be lost) also keep in mind that you need to be more specific when calling information when multiple players would use the application for more details check... http://unity3d.com/support/documentation/ScriptReference/PlayerPrefs.html Thank you for the help. I will try this tomorrow and I hope this will work ;) thanks
Jan 05 '12 at 10:20 PM
worldofcars
noone of this scripts are working:( is there anyone with a working script or description?
Jan 06 '12 at 07:02 PM
worldofcars
What code do you have so far ?
Jan 07 '12 at 12:29 PM
inkspots
at the moment I don t have any code. Your code isnt working. Maybe you have an other one?
Jan 07 '12 at 12:38 PM
worldofcars
(comments are locked)
|
EDIT: My mistake, I didn't realize you want this to work over different game sessions. What you could do is have a script that saves Application.loadedLevel to PlayerPrefs and have the first scene have nothing but a script that'll retrieve the PlayerPrefs and load said level. Pretty simple, really, here's untested code, to put once on the initial scene, where the player cannot go back. is not working
Jan 06 '12 at 07:19 PM
worldofcars
(comments are locked)
|
|
use an if statment if (Input.GetButtonDown("Jump")) { Application.LoadLevel ("The name of your level"); } The "Jump" button is referring to the Space key if you want you can also use Input.GetKeyDown(KeyCode.whatever key you want pressed)) If you want to load the previous level each time, just make separate scripts. So for example lets say you have 4 levels and you want to go back one level each time the user presses the A key. so if your in level 4, the script you would have would look like this if (Input.GetKeyDown(KeyCode.A)) { Application.LoadLevel (3); } This will take you back to level 3, now you want to go to level 2, so in your level 3 the script would be this if (Input.GetKeyDown(KeyCode.A)) { Application.LoadLevel (2); } and so on. so Just make the scripts different for each level, be sure that each script is its own separate script and your not just editing the same one over and over again. You don't understand my question. I want it like this: If the player reach level 10 and close the game and restart it after a few minutes, than I want this automaticly to load level 10 and not 0 ... do you understand this now?
Jan 05 '12 at 09:25 PM
worldofcars
ahh I see, ok I know what your saying now. Thats a good question. Im not very sure on this one, but you might need to use Application.LoadLevel(Application.loadedLevel)somehow. but still im not to sure how to get this working maybe this can help you? http://answers.unity3d.com/questions/198878/restart-current-level.html
Jan 05 '12 at 09:43 PM
snowconesolid
Thank you for the answers. I will see this tomorrow;)
Jan 05 '12 at 10:22 PM
worldofcars
(comments are locked)
|
