利用键值对的存储方式
存值的方法: PlayerPrefs.SetString("Name",t);//SetInt,SetFloat
取值的方法: PlayerPrefs.GetString("Name","无");//GetInt,GetFloat 第二个参数为默认值
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class TextTest : MonoBehaviour
{
// Start is called before the first frame update
public Text text;
public InputField ifd;
public void Submit(){//提交(保存)
string t= ifd.text.ToString();
PlayerPrefs.SetString("Name",t);
}
public void Delete(){//删除
if(PlayerPrefs.HasKey("Name")){
PlayerPrefs.DeleteKey("Name");
}
//删除所有键
// PlayerPrefs.DeleteAll();
}
public void UpLoad(){//上传
text.text=PlayerPrefs.GetString("Name","无");
}
}
手机扫一扫
移动阅读更方便
你可能感兴趣的文章