- Home /
Help with Object position and state, save and load.
Hi, I have a number of "brick" prefabs in my scene (cubes with explosion script and scoretrigger scripts)
I have 4 prefabs, (all the bricks have been manually placed into my scene): bluebrick, greenbrick, redbrick & yellowbrick. Each are tagged with "brick".
What I want to be able to do is, when the player saves (from my pause menu), it stores each brick's position on screen and if it is destroyed or still there.
for example; if the player is playing and destroys 25/100 bricks and then saves the game, quits and reloads, the level will load and the 25/100 bricks will still be destroyed.
I have been searching for about a week and i'm just lost. Is there a way using PlayerPrefs to just save:
1) the position of the bricks. 2) whether it is there in scene or already been destroyed.
The latest thing I tried was using this script:
http://gamingirresponsibly.com/megabite-24-saving-and-loading
as you can see from my comment this didn't work out lol arrrgh!
please help
Did you try out my Unity Serializer? I could help you trying to get that to work...
I had a look at it (i think it'd work) I watched your new video earlier. But I don't know how i'd fit it in with my save button on my pausemenu etc. I'm importing it now going to have a go at it :)
got this error when i imported it:
VerificationException: Error verifying TransformExtensions:LastAncestorOfType (UnityEngine.GameObject): Invalid generic method instantiation of method .Radical::FindImplementor (generic args don't respect target's constraints) at 0x001e UniqueIdentifier.FixName () (at Assets/Plugins/Serialization/UniqueIdentifier.cs:90) EditorNameFixer.Update () (at Assets/Plugins/Serialization/EditorNameFixer.cs:32)
What from the asset store version???? Ugh - that's not supposed to have that file :(
Sorry - I also added a damn mod to the code on that Asset Store package :( Right so just make it:
LevelSerializer.SaveGame("BrickGame", false, null);
Answer by whydoidoit · Jun 21, 2012 at 11:57 PM
Solved by using Unity Serializer to store the position and existence of the bricks and added script to the pause menu to save and load the game.
var paused : boolean = false;
var pausedGUI : GUITexture;
pausedGUI.enabled = false;
function Update ()
{
if(Input.GetKeyUp(KeyCode.P))
{
paused = !paused;
if(paused == true){
Time.timeScale = 0.0;
pausedGUI.enabled = true;
} else {
Time.timeScale = 1.0;
pausedGUI.enabled = false;
}
}
}
function OnGUI() {
if(!paused)
return;
var box : GUIStyle = "box";
GUILayout.BeginArea(Rect( Screen.width/2 - 200,Screen.height/2 - 300, 400, 600), box);
GUILayout.BeginVertical();
GUILayout.FlexibleSpace();
if(GUILayout.Button("Save Game"))
{
LevelSerializer.SaveGame("BrickGame", false, null);
}
GUILayout.Space(60);
for(var sg in LevelSerializer.SavedGames[LevelSerializer.PlayerName]) {
if(GUILayout.Button(sg.Caption)) {
sg.Load();
Time.timeScale = 1;
}
}
GUILayout.FlexibleSpace();
GUILayout.EndVertical();
GUILayout.EndArea();
}