- Home /
Am I miss using: application.loadlevel(x);
Hello, I'm having a hard time understanding how to as a beginner put my game together. So far all the tutorials are either to far advanced, or they use java script, where I'm just focusing on C# right now, I don't want to learn 2 lang, and C# is more natural for me, since I'm trained in the basics of VBA for user form macro's.
So I'll just describe in a nut shell what scene's I have and what I set them to do. scene 0: title screen, with gui button, start game, options, and quit. scene 1: character creation, this is where you will create your character and set its base parameters. with a game object that holds a script containing nothing but the final base parameters to be made a child in other game scenes for loading those base stats. several other game objects with the base stat modifiers based on conditions, like buff, DE buff, fatigue, enraged, racial fear/hatred, weapon proficiency, armor proficiency. these will be instantiate and destroyed as needed. scene 2: main menu, will save/load game, have in game option settings, an encyclopedia of game objects, a help menu, game map tab, quest tab, stats, level up, everything the game has for displaying game data here. scene 3: main starting area, you can switch from top down to First person, and drop buildings on map somewhat like a SimCity object placement, and you can enter each building with a door from first person. scene 4: building internals, this scene will load the environment based on which type of building you entered, is it a store, or inn, or home.
now that you know what I'm doing, my problem is, I can as intended go from location to location, but my character location in the world is always going back to the default starting spot, the buildings I drop do not exist when coming back to that scene, the character stats are reset to default when swapping scenes, and they only exist in the character creation scene.
Can someone please help me understand what I should be doing to make this work? Thank you very much.
Since you seem to be looking for a tutorial based on your reply to kubci98. An extremely good video tutorial series that covers about everything you mentioned and a whole lot more can be found at http://www.burgzergarcade.com/hack-slash-rpg-unity3d-game-engine-tutorial. The author Petey starts with day 1 never touched Unity and takes you through about everything that is required to build a very advance RPG style game with all the bells and whistle. The series is over 280 videos long so far. Oh, another point you should like is every line of his code is written in C#. Good luck with your projects.
I've tried this tutorial series, and am up to video 25 or something, and he mentions quite often that he's waiting for the new version of unity, and things will change. He said this for the GUI stuff mostly, and that he intends on using a sprite plug in or something when he gets to the point where its ready for proper GUI, which he said is a paid tool. Very frequently I get compile errors in yellow and sometimes in red, with the editor telling me out of date or obsolete. His tutorial starts in unity version 2.5 or something. So I'm confused as to following it when I'm using unity 4.1 . Can you confirm if this is only a $$anonymous$$or conflict in engine versions? Thank you for previous posts.
He is probably using NGUI. You can skip GUI parts and learn about Unity GUI. Yellow compile errors are mostly just warnings, or not important. Compiler can repair these errors. You can try to google the error code.
Answer by amphoterik · Jun 25, 2013 at 12:53 PM
You can find a lot of information about saving things in Unity by searching for the terms alucardj posted.
For PlayPrefs (my favorite), check here: http://docs.unity3d.com/Documentation/ScriptReference/PlayerPrefs.html
Good info on "DontDestroyOnLoad" can be found here: http://answers.unity3d.com/questions/12762/how-to-keep-certain-information-when-reloading-a-l.html
Thanks amphoteric =]
Agreed, PlayerPrefs should be perfect for most applications.
I've also done a couple of answers on Singletons, mainly for music players, but the principle is the same. Before changing scene, assign values to some variables on the singleton. When the next scene loads, at Start simply read back those variables, apply them and away you go. eg :
// before loading next level
$$anonymous$$ySingleton.Instance.playerStartPos : Vector3 = player.transform.position;
$$anonymous$$ySingleton.Instance.playerHealth : float = player.health;
// after loading the next level
player.transform.position = $$anonymous$$ySingleton.Instance.playerStartPos;
player.health = $$anonymous$$ySingleton.Instance.playerHealth;
Example of a Singleton and DontDestroyOnLoad : http://answers.unity3d.com/questions/413203/continuous-music-across-multiple-scenes.html
( upvote welcome if you're inclined to do so ;)
Thank you very much for the detailed reply. I've read in a YouTube tutorial cant remember which one, but it said using PlayerPrefs is possibly a bad habit, because 1: if your file directory changes, the compiler shows errors. and 2: players can easily alter data with a notepad or something. and 3: they said it only has 1 player save with 1 generic load state. Is this true?
You are correct. PlayerPrefs can be a bad thing, but it is all about context. I prefer them for ease, but I would not use them for things that would allow a player to cheat. I like them for configuration options.
Ok, I guesss I entered the text wrong, it dident show up with the picture. Is this a logic flow that looks sound? Im still trying to find a for dummies tutorial on how to write a save file that is just gibberish in notepad works for overwriting and retrieving its information in unity. I fully understand each tutorial on what ever its covering in the scope of itself, but its just not clicking on how to get them to continue to work as made when loaded into a new project, the different small packs seem to act like oil and water when put in the same environment.
Answer by kubci98 · Jun 23, 2013 at 03:58 PM
All variables are stored in scripts attached to objects in scene. If you load a scene, all are reseted to normal. You have to save stats and all other info and then load them when you load the scene.
Ok, and where does someone with no saving and loading knowledge go for a user friendly tutorial from step 1?
Search on these keywords :
PlayerPrefs
Singleton and DontDestroyOnLoad
Unity Serializer