Load and Save Game (GUI) (proposal with image)

I need a script that load the level and save the level.

http://unity3d.com/support/documentation/Components/GUI%20Scripting%20Guide.html
http://unity3d.com/support/documentation/ScriptReference/PlayerPrefs.html

PlayerPrefs.SetInt(“level”, 3); ?
PlayerPrefs.GetInt(“level”); ?
I do not know how to use it. I need a specific script.

Why should we create your scripts? Did you even try it by yourself?

I’m sorry to say there is no magic one-stop script solution for the issue of saving and loading games; you need to write one specific to your actual product.

Basically, you need to break down every piece of information you need to remember and store it in PlayerPrefs. You can store a ton of little values (like say PlayerPrefs.SetFloat(“savegamenamePlayerHealth”, 85) to store the player’s health as 85), or you can serialize the data and store a few large strings that you can deserialize later.

This is largely something you need to work out yourself though, as it is incredibly unique and specific to the game you are creating. Unity does not have any “save the state of the engine” - “resume state” functionality while playing.

I know how to do that I value is stored (PlayerPrefs.SetInt (“level”, 3)
But I do not know how to read it to me (PlayerPrefs.SetInt (“level”, 3)) 3 level.

translate.google:

Try GetInt and not SetInt to read a value back. And please, dont write in slovak write in english.

Somehow still do not understand, you can not make me a sample script.

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour
{
    void Start()
    {
        var numberOfStarts = PlayerPrefs.GetInt("NumberOfStarts");
        numberOfStarts++;
        PlayerPrefs.SetInt("NumberOfStarts", numberOfStarts);
        Debug.Log("Script has been started: " + numberOfStarts + " times and the one who uses this script is a lazy mule for not trying to script by himself.");
    }
}

Hmm … I’m sorry, but I need a solution.
Just gui buton save and load game (only scene).

ok here is a try but people above have pretty much said the answer.

if(GUI.Button(Rect(1,1,1,1),"Save")){
PlayerPrefs.SetInt ("level ", 3);
}
if(GUI.Button(Rect(2,2,2,2),"Load")){
PlayerPrefs.GetInt ("level ");
}

Ok, try this, it has a Load and a Save Button, also it stores the LevelNumber into the PlayerPrefs and reads from it:

using UnityEngine;
using System.Text;
using System.Collections;

public class example : MonoBehaviour
{
    bool isLoading = false;
    bool isSaving = false;
    string progressText;
    string[] somethingToMakeTheScriptLookFat;
    
    void Start()
    {
        var oldLevel = PlayerPrefs.GetInt("MarrrksLevel");
        if (oldLevel == 0)
            progressText = DecodeFrom64("SG93IGFib3V0Li4uIE5PISBZb3Ugd2FudCB0byBkbyBpdCwgc28gZG8gaXQgeW91cnNlbGYh");
        else
            progressText = DecodeFrom64("Tm90aGluZyB3aWxsIGNoYW5nZSwgdGhlIHNjcmlwdCBpcyBvbmx5IHRvIGdpdmUgeW91IHNvbWV0aGluZyB0byBhbm5veSB5b3UgbGlrZSB5b3UgYW5ub3llZCBtZS4=");
    }
    
    void OnGUI()
    {
        if (isSaving || isLoading)
        {
            GUI.Label(new Rect(10, 10, 600, 20), progressText);
            return;
        }
        
        if (GUI.Button(new Rect(10, 10, 50, 50), "Save"))
            isSaving = true;

        if (GUI.Button(new Rect(10, 70, 50, 30), "Load"))
            isLoading = true;
            
        if (isSaving || isLoading)
        {
            somethingToMakeTheScriptLookFat = new string[]
            {
                "{E88F81CE-1EEB-4DC2-A36E-AC443542A19C}",
                "{2FEBB4C7-6935-4BCB-92EA-A99FD7061AA9}",
                "{715CE6C4-5E67-4893-A389-44CF2318E058}",
                "{12A94812-598B-420C-B5D8-54FEDC8B909B}",
                "{8A297F40-01AF-405E-8D48-C87F67DA6EB2}",
                "{9D33E2D2-E209-4294-A95A-38A7B42EE004}",
                "{1BF0DCAD-D534-4EA1-B588-71F4FF7BC6B1}",
                "{6B381179-4214-480C-B045-79B9193D5918}"
            };
            PlayerPrefs.SetInt("MarrrksLevel", 1);
        }
    }
    
    string DecodeFrom64(string encodedData)
    {
        var decodedBytes = System.Convert.FromBase64String(encodedData);
        var decodedData = Encoding.UTF8.GetString(decodedBytes);

        return decodedData;
    }
}

falin: Thank you, but the "load"to not load saved Level

Marrrk: In script is error, "Unexpected symbol “if” "

Oh I am sorry, I fixed the error, try again.


http://s1.imgupload.cz/img/307140/ch4iw/error.PNG

Rename the file to example.cs


http://s1.imgupload.cz/img/307141/5Eoj8/error2.PNG

Try again, I missed a System. in front of Convert.

nothing will change, the script is only to give you something to annoy you like you annoyed me.
what ?