Hello, I’m trying to make a save script for multiple saves, it’s just a notepad so all it saves is the custom name and the note. I had it working with single saves, so I tried rewriting it to work with multiple saves and just called them “NoteContents1”, “NoteContents2” and so on. But when I click the OkayButton() it doesn’t save anything, I think the variable noteSave just resets to 0?
Here’s my code, I understand it’s very sloppy, but I’m working on limited C# skills here
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class SaveControl : MonoBehaviour
{
public string theText1;
public string theName1;
public string theText2;
public string theName2;
public GameObject ourNote;
public GameObject namePlaceHolder;
public GameObject placeHolder;
public GameObject customName;
static int noteSave;
public void LoadButton1()
{
{
SceneManager.LoadScene(1);
noteSave = 1;
theText1 = PlayerPrefs.GetString("NoteContents1");
theName1 = PlayerPrefs.GetString("theName1");
placeHolder.GetComponent<InputField>().text = theText1;
namePlaceHolder.GetComponent<InputField>().text = theName1;
string customName = theName1;
}
}
public void LoadButton2()
{
noteSave = 2;
theText2 = PlayerPrefs.GetString("NoteContents2");
theName2 = PlayerPrefs.GetString("theName2");
placeHolder.GetComponent<InputField>().text = theText2;
namePlaceHolder.GetComponent<InputField>().text = theName2;
string customName = theName2;
SceneManager.LoadScene(1);
}
public void LoadButton3()
{
noteSave = 3;
theText3 = PlayerPrefs.GetString("NoteContents3");
theName3 = PlayerPrefs.GetString("theName3");
placeHolder.GetComponent<InputField>().text = theText2;
namePlaceHolder.GetComponent<InputField>().text = theName2;
string customName = theName3;
SceneManager.LoadScene(1);
}
public void OkayButton()
{
if (noteSave == 1)
{
theText1 = ourNote.GetComponent<Text>().text;
theName1 = customName.GetComponent<Text>().text;
PlayerPrefs.SetString("NoteContents1", theText1);
print(theName1);
SceneManager.LoadScene(0);
}
else if (noteSave == 2)
{
theText2 = ourNote.GetComponent<Text>().text;
theName2 = customName.GetComponent<Text>().text;
PlayerPrefs.SetString("NoteContents2", theText2);
print(theName2);
SceneManager.LoadScene(0);
}
}
}
Any help would be appreciated! Thanks!