SaveLoad Profile c# to xml

welp , i changed the stone system for a bit more gems

here what im trying to do , i just want to bein able to save and load the number of gems of the player , if he have the equipment on , and how mutch shield , his name , and his code

i did read the tutorial about the monsters in xml but the fact im french dont realy help in the translation . i have limited vocabulary and i have no idea who you must use the script to load and save

here what i got so far

the GameSystem.cs


using UnityEngine;
using System.Collections;
using System;
using System.Text;
using System.IO;
using System.Collections.Generic;
using System.Xml;
using System.Xml.Serialization;




public class GameSystem : MonoBehaviour
{



//--------------------------------------------------------------//

[XmlAttribute("Profile")]


public string Name = "Name";
public int emerald = 0;
public int sapphire = 0;
public int ruby = 0;
public int hellstone = 0;
public int Token = 0;

public int shields = 0;

public int equips = 0;

public bool god = false;

public bool jetpack = false;

public int code = 0;




//-------------------------------------------------------------//





// Use this for initializationname
void Start ()
{



}

// Update is called once per frame
void Update ()
{


}


}


__________________________________________________ ____________

and the ProfileContainer.Cs

__________________________________________________ ____________


using System.Collections.Generic;

using System.Xml;

using System.Xml.Serialization;

using System.IO;



[XmlRoot("MonsterCollection")]

public class ProfileContainer

{

[XmlArray("Gems"),XmlArrayItem("Gem")]

public Gem[] Gems;



public void Save(string path)

{

var serializer = new XmlSerializer(typeof(ProfileContainer));

using(var stream = new FileStream(path, FileMode.Create))

{

serializer.Serialize(stream, this);

}

}



public static ProfileContainer Load(string path)

{

var serializer = new XmlSerializer(typeof(ProfileContainer));

using(var stream = new FileStream(path, FileMode.Open))

{

return serializer.Deserialize(stream) as ProfileContainer;

}

}

public static ProfileContainer LoadFromText(string text)

{

var serializer = new XmlSerializer(typeof(ProfileContainer));

return serializer.Deserialize(new StringReader(text)) as ProfileContainer;

}

}

i did more than asking for everything like the last question but since here , i know there still problems and i dont know how to save them things and how to use the save function and load function from the container

if someone can just explain me how it work so i understand for when ill be to saving the unlocked level (they will be bool)

Props to GameFreak. More info:
You can do booleans by using this script: unifycommunity.com

Names like PlayerPrefs.GetString (“PlayerName”);

Here.
See its really really simple.

http://unity3d.com/support/documentation/ScriptReference/PlayerPrefs.html

This is the documentation.

Now when you need to save something. for example you have

private int gems;

//gems are the number of gems so after all gems have been added use

if (gems> PlayerPrefs.GetInt(“GEM”)) { PlayerPrefs.SetInt(“GEM”, gems);

PlayerPrefs.Save();
}

and whenever you need the number of gems use

private var gems1 = PlayerPrefs.GetInt (“GEM”);

So you ll get the number of gems you stored earlier

About the position. Just place it wherever the gems are? Like exactly if you are using this you wont use xml right?
So whenever you want to save gems use SetInt and whenever you want them use getInt

As said above bools can be saved by SetString And GetString

For new script use something like-

var gems= Script1.gems1;

if (something happens)

{

var gems +=1;

}

if (gems> PlayerPrefs.GetInt(“GEM”)) { PlayerPrefs.SetInt(“GEM”, gems);

PlayerPrefs.Save();

}

Now in the first scirpt (script1)of the game use
void Start ()
{

private var gems1 = PlayerPrefs.GetInt (“GEM”);

}

learned some more … tank you , but once again lost with some translation and aint working how i would expect … maybe im just too retarded to understand

can you please make some premade of what i have as variable up there because when try it it gime me errors about variable assignment D:

sorry to be anoying and redundant … i just need more secificated and almost premade code so i can understand what do what :c

Its tough posting it as a comment so I ll post it as a new answer

Script.cs
private int ruby = script1.ruby1;

private int saffire = script1.saffire1;

private int emarald = script1.emerald1;

private int jetpack = script 1.jetpack1;

void OnCollisionEnter(col:Collision)
{

If (col.gameObject.tag == "Ruby"){

ruby += 1;
}
Else If (col.gameObject.tag == "Saffire") {
saffire += 1;
}
Else If (col.gameObject.tag == "Emerald") {

Emerald += 1;

}
Else if (col.gameObject.tag == "Jetpack"
{
Jetpack += 1;
}

void Update ()
{
If (ruby != PlayerPrefs.GetInt("Ruby") {
PlayerPrefs.SetInt ("Ruby",ruby);
}
  If (ruby != PlayerPrefs.GetInt("Saffire") {
PlayerPrefs.SetInt ("Saffire",saffire);
}
  If (ruby != PlayerPrefs.GetInt("Emerald") {
PlayerPrefs.SetInt ("Emerald",emerald);
}
  If (ruby != PlayerPrefs.GetInt("Jetpack") {
PlayerPrefs.SetInt ("Jetpack",jetpack);
}

Now script1.cs (To be placed wherever the game begins)

private int ruby1;
private int saffire1;
private int emerald1;
private int jetpack1;

void Start ()
{


ruby1 = PlayerPrefs.GetInt ("Ruby"); 
saffire1 = PlayerPrefs.GetInt ("Saffire");
emerald1 = PlayerPrefs.GetInt ("Emerald"); 
jetpack1 = PlayerPrefs.GetInt ("Jetpack");
}

Untested but should work