1、使用方法
(1)存储数据
PlayerPrefs.SetString(“Name”,”ms”); //设置String类型
PlayerPrefs.SetInt(“Age”,20); //设置Int类型
PlayerPrefs.SetFloat(“High”,168.0f); //设置Float类型
PlayerPrefs.Save(); //保存数据
(2)读取数据
PlayerPrefs.GetString(“Name”); //获得Name
Playerf.GetInt(“Age”); //获得Age
PlayerPrefs.GetFloat(“High”); //获得High
2、游戏脚本中的实际运用
(1)数据保存脚本Data.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Data : MonoBehaviour
{
public static Data Instance; //设置单例
void Start()
{
Data.Instance = this;
}
//保存数据方法
public void SaveData(int num)
{
PlayerPrefs.SetInt("score", num);
PlayerPrefs.Save();
}
//读取数据方法
public int GetData()
{
return