|
what im trying to do is add a save load feature into my game, i want to save the location fo all the cubes in the game. i'm using the arrayprefs script from http://www.unifycommunity.com/wiki/index.php?title=ArrayPrefs. i have my save function working but i cant figure out how to load the game from my main menu scene. Here is my load function. this script is in my main menu.
button2 is my saving script is in my first level, here is what the save function looks like for that level.
What am i doing worng? EDIT** here are my new scripts. This is my CubeManager script that is attached to empty gameobjects in the first level and the main menu.
Here is my script that is in my first level to save the cubes.
Here is my script that is attached to my load button on the main menu to call the load function:
(comments are locked)
|
|
Are you saving your Never used edit
!!not tested!! edit2 If this script is called "CubeManager" you can use this from any other script as long as the CubeManager is attached to a GameObject in the scene:
ps. fixed a typing mistake the second SaveCubes should be LoadCubes of course ;) do you know how to save to an XML file? i just need to be able to save my game
Apr 05 '11 at 11:53 PM
austen 2
Well, that depends on the platform. Web-buids can't write files, but in standalone you can use the xml classes that comes with Mono: http://www.go-mono.com/docs/index.aspx?link=T%3aSystem.Xml.XmlWriter I haven't used it yet so i can't go in detail here, but why don't you use the PlayerPrefs(X)? I can post an example if you want. You need only the positions of the cubes, right?
Apr 06 '11 at 12:21 AM
Bunny83
im trying to use the LoadCubes function outside of my scene (in the main menu), so i can load from the main menu. but when i try to make the createcube function static, it gives me an error because cube2 is not satic but if i make it static i cant assign a prefab to it. how do i load frorm the main menu?
Apr 06 '11 at 01:52 PM
austen 2
To what object is that script attached to? All that stuff like Createcube / saveing / loading and storing is a global task so you should place it on a manager object that is already in the scene
Apr 06 '11 at 01:58 PM
Bunny83
If you have this script somewhere in the scene you just have to find the GameObject and use GetComponent to get your script reference. Then you can call any public function. If there is only one instance of this script you can use FindObjectOfType to get the script reference directly. I can add an example to my answer.
Apr 06 '11 at 02:05 PM
Bunny83
(comments are locked)
|
