PlayerPrefs 的 API
public int age;
public float top;
public Text text_age;
public Text text_top;
public Button ageBtn;
public Button topBtn;
public Button clearBtn;
public void Start()
{
text_age.text ="age:"+ PlayerPrefs.GetInt("age").ToString();
text_top.text = "top:" + PlayerPrefs.GetFloat("top").ToString();
ageBtn.onClick.AddListener(() =>
{
PlayerPrefs.SetInt("age", age);
text_age.text = "age:" + PlayerPrefs.GetInt("age").ToString();
});
topBtn.onClick.AddListener(() =>
{
PlayerPrefs.SetFloat("top", top);
text_top.text = "top:" + PlayerPrefs.GetFloat("top").ToString();
});
clearBtn.onClick.AddListener(() =>
{
PlayerPrefs.DeleteAll();
text_age.text = "age:" + PlayerPrefs.GetInt("age").ToString();
text_top.text = "top:" + PlayerPrefs.GetFloat("top").ToString();
});
}
预览图:
|