How do I serialize a class?

Hello, I am trying to make a class of variables that are hidden (serialized). This is similar to the playermotor script that comes with unity. You have the little arrow to extend the field.

Also, there is no active/ non active check box next to the script however i don’t know if this a problem or not.

How do I achieve this?
So far I have this code but nothing shows up:

using UnityEngine;
using System.Collections;

public class Script : MonoBehaviour {

	[System.Serializable]
	public class example
	{
		public float myFloat = 1;
	}
}

Make a field of your serializable class in your script.

[System.Serializable]  // This allows fields of this type to appear in the inspector
public class Example {
  // These fields will become visible when the arrow is clicked
  public float myFloat = 0.1f;
}

// This is your script on the game object
public class Script : MonoBehaviour {
  public Example field;
}

Hello,
Do it like that:

using UnityEngine;
using System.Collections;
using System.Xml.Serialization;
using System.IO;
public class Script : MonoBehaviour {
    public class Example
    {
        public float myFloat = 1;
    }
    public void serializeExample(Example example) {
        XmlSerializer serializer = new XmlSerializer(typeof(Example));
        TextWriter writer = new StreamWriter("saveFile.xml");
        serializer.Serialize(writer, example);
        writer.Close();
    }
}

I didn’t test it, but it should work :slight_smile:

Good luck!