首页 > 技术文章 > unity本地存取

AllNighter 2021-06-18 20:40 原文

using UnityEngine;
using System.Collections;

public class local_storage : MonoBehaviour {

    // Use this for initialization
    void Start () {
        //设定数据----不是代码
        // name: 小红 // 字符串
        // age: 12 // 整数 
        // sex: 1 // 性别
        // hight: 1.62 // float

        //存数据
        /*PlayerPrefs.SetString("name", "小红");
        PlayerPrefs.SetInt("age", 12);
        PlayerPrefs.SetInt("sex", 1);
        PlayerPrefs.SetFloat("hight", 1.62f);
        PlayerPrefs.Save();*/

        //取数据
        // Debug.Log(PlayerPrefs.GetString("name"));
        // Debug.Log(PlayerPrefs.GetInt("age"));
        // Debug.Log(PlayerPrefs.GetInt("sex"));
        // Debug.Log(PlayerPrefs.GetFloat("hight"));

        //查找删除
        if (PlayerPrefs.HasKey("name")) {
            Debug.Log("Haskey");//第一次输出这个
            PlayerPrefs.DeleteKey("name");
        }
        else {
            Debug.Log("ELSE NOT FOUND");//第二次输出这个(被第一次删除了,找不到了)
        }
    }
    
    // Update is called once per frame
    void Update () {
    
    }
}

 

推荐阅读