Я хочу, чтобы при нажатии на кнопку сохранялась переменная (а так же при выходе из игры) и при нажатии на другую кнопку, переменная загружалась. Вот мои скрипты:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Save : MonoBehaviour
{
// Start is called before the first frame update
MainScene silic = new MainScene();
void Start()
{
silic.silicon = PlayerPrefs.GetInt("sil");
print("loadd");
}
void OnMouseDown()
{
PlayerPrefs.SetInt("sil", silic.silicon);
PlayerPrefs.Save();
print("save");
}
public void OnApplicationQuit()
{
PlayerPrefs.Save();
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Load : MonoBehaviour
{
// Start is called before the first frame update
MainScene silic = new MainScene();
void OnMouseDown()
{
silic.silicon = PlayerPrefs.GetInt("sil");
print("loadd");
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class MainScene : MonoBehaviour
{
public int silicon;
// Start is called before the first frame update
void Update()
{
}
}
Ничего не происходит при нажатии на кнопки или при перезаходе. Всегда переменная сбрасывается.
P.s. Игру делаю под андроид