// Method for saving data out to a file // 1. Create BinaryFormatter // 2. Create file to save to // 3. Create a container for the object // 4. Write the container to the file // 5. Close the file public void SaveButtonAssignment() { // BinaryFormatter is the thing that is going to write for us BinaryFormatter bf = new BinaryFormatter(); // persistantDataPath is a Unity specific place to hide save data. // Application.persistantDataPath is a string, so you can output the full path if // you want to know exactly where the data is being stored // playerInfo.dat is a data file inside of persistantDataPath where we will store the players info. FileStream file = File.Create(Application.persistentDataPath + "/buttonAssignment.dat"); // Take data from ButtonControl and put it in ButtonData container ButtonData data = new ButtonData(); data.SetButtonLeft(left); data.SetButtonRight(right); data.SetButtonUp(up); data.SetButtonDown(down); data.SetButtonJump(jump); data.SetButtonFire1(fire1); data.SetButtonFire2(fire2); data.SetButtonFire3(fire3); data.SetButtonQuickFire(quickFire); data.SetButtonSubmit(submit); data.SetButtonCancel(cancel); // Now, write that container to a file // Takes serializable class "data", and writes it to "file" bf.Serialize(file, data); // Close the file file.Close(); }