|
I want to load a new scene (using Or will I have to write what I need to the PlayerPrefs and then read them on the new scene?
(comments are locked)
|
|
sebas's answer is correct and you have other ways to do this too. you can have a static class called SceneProperties and have a list of properties in it or have a list in it to set it's items. unfortunately none of the methods like LoadLevel and Instantiate don't get additional parameters to send to new objects or all objects in the new scene. so you need to store data in a static class or a GameObject that won't destroy with the scene or put the in prefs. the first method is the best and fastest one and the last one is the slowest and even can fail and is not good for web games. you can easily get exceptions with player prefs so use static classes. unfortunately you can not get the name of current scene and you should use another way to find out what scene you are in. to create static classes and variables use "static" keyword. you don't need to create them and one instance of them will be created at the first frame or even before it and you can set it's properties or add items to it's lists or call it's methods. they are the best solution for creating managers.
(comments are locked)
|
|
Maybe don't destroy an object from the old scene by using Don'tDestroyOnLoad and then assigning a variable of that object to something else in your new scene in a Start() or Awake() function? That usually should do the trick. related questions: http://answers.unity3d.com/questions/841/scene-connecting http://answers.unity3d.com/questions/3416/retaining-gameobject-data-when-switching-scenes
Feb 08 '10 at 08:07 PM
Sebas
(comments are locked)
|
|
You can create an object in first scene, attach a sript to it and sen value of variable in this script. For example if you want to send user login script attachet to game object that will survife after second scene load should be:
Set userLogin in first scene and read in second. Complete example can be found in my blog http://unity-tutorials.blogspot.com/. Listing 20 and 21. Given that you are posting the same answer as someone else - perhaps a comment that you have a tutorial would be more appropriate and less confusing for future readers (plus it would be associated with the ticked answer and not appear at the bottom of the list).
Mar 30 at 01:31 PM
whydoidoit
BTW the tutorial is nice. If you want to get some exposure we'd be happy to have you cross post quality work like this on Unity Gems which already has a high level of traffic (1-2k visitors per day) and we are always on the look out for good authors to submit relevant work. I'm writing here because I can't comment on your tutorial or find another way of getting in touch.
Mar 30 at 01:36 PM
whydoidoit
(comments are locked)
|
