I am very new to Unity, and programming languages in general, so forgive my noobiness lol.
I am making a notepad, and I have been trying to figure out how to get multiple notes as well as the title of the note. I have a basic script for saving notes, which worked for one note, but I don't know how to save multiple notes. I even tested making 2 saves and wasn't able to.
Here's the script I had, full disclosure, I wrote half of it following a tutorial, the other half was my attempt at making multiple saves
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class SaveControl : MonoBehaviour
{
void Awake()
{
DontDestroyOnLoad(gameObject);
}
public string theText1;
public string theName1;
public string theText2;
public string theName2;
public GameObject ourNote;
public GameObject namePlaceHolder;
public GameObject placeHolder;
public GameObject customName;
[SerializeField]
public int noteSave = 1;
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 OkayButton()
{
if (noteSave == 1)
{
string key = "NoteContents" + noteNumber;
Debug.Log("key is '" + key + "'");
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);
}
}
}
Sorry it's super sloppy, I just started Unity like a week ago. I'm guessing the problem is partly that the noteSave variable isn't global so it just get's reset between scenes.
Any help would be greatly appreciated!