- Home /
Unity - keep created buttons after quit
Hello, is there any way to keep/save created buttons with simple text, to stay even after the application/play mode shuts down?
public InputField Input;
public GameObject itemTemplate;
public GameObject content;
public string StringInput;
public void addButton_Click(){
StringInput = Input.text;
var copy = Instantiate(itemTemplate);
copy.transform.parent = content.transform;
copy.GetComponentInChildren<Text>().text = (StringInput).ToString();
Input.text = ("");
List.Add(StringInput);
copy.GetComponent<Button>().onClick.AddListener( ()=> {
Destroy(copy.gameObject);
List.Remove(copy.GetComponentInChildren<Text>().text);
});
}
Comment
Answer by knobblez · Jan 29, 2020 at 05:01 PM
Save game. I don't know the proper way, but you could make a script that writes to a txt file(save name = txt file name) and uses numbers to represent whether or not buttons are shown. In the Load script have the user select the saved game and it will read that txt file line-by-line.