I wrote a script to save the settings and a script to change them are two separate files and there is a problem with line 12 of the file "setting". , maybe I made a mistake somewhere. setting.cs: Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Audio; using System.IO; using System.Runtime.Serialization.Formatters.Binary; public class setting : MonoBehaviour { UIScript uiset = new UIScript(); float volumeS = uiset.volume; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { } } [System.Serializable] public class SaveSetting { public SaveSetting(setting seting) { } } public static class SaveLoadSet { private static string path = Application.persistentDataPath + "/settings.sndS"; private static BinaryFormatter formatter = new BinaryFormatter(); public static void SaveSettings(setting seting) { FileStream fs = new FileStream(path, FileMode.Create); SaveSetting data = new SaveSetting(seting); formatter.Serialize(fs, data); fs.Close(); } public static SaveSetting LoadSettings() { if (File.Exists(path)) { FileStream fs = new FileStream(path, FileMode.Open); SaveSetting data = formatter.Deserialize(fs) as SaveSetting; fs.Close(); return data; } else { return null; } } } UIScript.cs: Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Audio; public class UIScript : MonoBehaviour{ public static float volume = 0; public int quality = 0; public bool isFullscreen = false; public AudioMixer audioMixer; private Resolution[] resolutions; private int currResolutionIndex = 0; public bool menuTrans = false; public bool pauseStatus = false; public bool EnventarOpen = false; public bool inTransport = false; public bool seting = false; public int torInt = 0; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.T)) MenuTransF(); if (Input.GetKeyDown(KeyCode.Escape)) Pause(); if (Input.GetKeyDown(KeyCode.E)) EnventarBo(); } private void OnGUI() { /*StartCoroutine(MenuTransport());*/ if (pauseStatus == true) { GUI.Label(new Rect(10, 10, 200, 100), "Pause"); if (GUI.Button(new Rect((float)(Screen.width / 1.5), (float)(Screen.height/20), Screen.width / 6, Screen.height / 8), "Settings")) { Debug.Log("Setting"); EnventarOpen = false; pauseStatus = false; menuTrans = false; seting = true; } } if (seting == true) { //GUI.Label(new Rect(10, 10, 200, 100), "Settings"); if (torInt==0) { //GUI.Slider(new Rect(25, 25, 100, 30), volume, 10.0f, 0.0f); volume = GUI.HorizontalSlider(new Rect(25, 25, 100, 30), volume, 0.0F, 100.0F); } if (torInt == 1) { } if (torInt == 2) { } if (torInt == 3) { } if (torInt == 4) { } } if (EnventarOpen == true) { } if (menuTrans == true) { GUI.Label(new Rect(10, 10, 200, 100), "Transport"); if (GUI.Button(new Rect((float)(Screen.width / 1.5), (float)(0), Screen.width / 6, Screen.height / 8), "Base")) { Debug.Log("hufyfg"); } if (GUI.Button(new Rect((float)(Screen.width / 1.5), (float)(0) + Screen.height / 8, Screen.width / 6, Screen.height / 8), "Player")) { Debug.Log("player"); inTransport = false; } } } public void ChangeVolume(float val) { volume = val; } public void ChangeResolution(int index) { currResolutionIndex = index; } public void QuitGame() { Application.Quit(); } void MenuTransF() { if (true) { menuTrans = !menuTrans; EnventarOpen = false; pauseStatus = false; seting = false; } } void EnventarBo() { EnventarOpen = !EnventarOpen; menuTrans = false; pauseStatus = false; seting = false; } void Pause() { pauseStatus = !pauseStatus; menuTrans = false; EnventarOpen = false; seting = false; } }
If a class inherits from MonoBehaviour, you can't create an instance of it with "new" You either have to use AddComponent to add it to a gameobject or GetComponent if you already added it to a gameobject. The other option is don't inherit from MonoBehaviour on your UIScript class if it doesn't need to be on a gameobject, but based on the class, that isn't the case. I suppose you could split the data you want to save with the methods that need to be on a gameobject, but at this point, I think you should get the basic issue.
That is not an actionable statement as there are ten million different ways to accomplish this task. Let me help you: How to report problems productively in the Unity3D forums: http://plbm.com/?p=220 Help us to help you.