PlayerPrefs学习
来源:互联网 发布:淘宝商品id 编辑:程序博客网 时间:2024/05/18 00:49
1、创建工程,添加两个场景scene0和scene1
2、创建两个C#文件
//Scene0Main.csusing UnityEngine;using System.Collections;public class Scene0Main : MonoBehaviour {public string testStr;public string testInt;public string testFloat;//public GUISkin fontSkin;// Use this for initializationvoid Start () { testStr = PlayerPrefs.GetString( "testStr", "default");testInt = PlayerPrefs.GetInt("testInt", 0).ToString();testFloat = PlayerPrefs.GetFloat ("testFloat", 0).ToString (); }// Update is called once per framevoid Update () {}void OnGUI(){testStr = GUI.TextField (new Rect(10,200,200,50), testStr, 50);testInt = GUI.TextField (new Rect (10, 250, 200, 50), testInt, 50);testFloat = GUI.TextField( new Rect(10, 300, 200, 50), testFloat, 50);if (GUI.Button(new Rect(220, 200, 150, 100), "commit all")) { PlayerPrefs.SetString("testStr", testStr); PlayerPrefs.SetInt("testInt", int.Parse(testInt)); PlayerPrefs.SetFloat("testFloat", float.Parse(testFloat)); Application.LoadLevel("scene1"); } }}
//Scene1Mainusing UnityEngine;using System.Collections;public class Scene1Main : MonoBehaviour {public string testStr; public string testInt; public string testFloat; // Use this for initializationvoid Start () {testStr = PlayerPrefs.GetString("testStr", "default"); testInt = PlayerPrefs.GetInt("testInt", 0).ToString(); testFloat = PlayerPrefs.GetFloat("testFloat", 0).ToString(); }// Update is called once per framevoid Update () {}void OnGUI(){GUI.Label(new Rect(10,150,300,50),"testStr = "+ testStr); GUI.Label(new Rect(10,200,300,50),"testInt = "+ testInt); GUI.Label(new Rect(10,250,300,50),"testFloat = "+ testFloat); if (GUI.Button(new Rect(220, 200, 150, 100), "clean all")) { PlayerPrefs.DeleteAll(); Application.LoadLevel("scene0"); } if (GUI.Button(new Rect(220, 320, 150, 100), "only return")) { Application.LoadLevel("scene0"); } }}
分别将两个脚本挂在对于场景的摄像机上,在File->Build Setting中,添加scene0和scene1两个场景,运行scene0。
0 0
- PlayerPrefs学习
- PlayerPrefs的学习
- 对于PlayerPrefs学习以及存储的研究
- PlayerPrefs类
- PlayerPrefs使用
- unity3d PlayerPrefs
- PlayerPrefs使用
- 封装PlayerPrefs
- Unity 3D--PlayerPrefs
- Unity PlayerPrefs 存储字段
- Playerprefs存储路径
- PlayerPrefs 游戏存档
- PlayerPrefs 游戏存档
- unity PlayerPrefs类扩充
- UNITY 5.2 PlayerPrefs类
- PlayerPrefs 位置 unity
- Unity3D PlayerPrefs的使用
- unity3d--PlayerPrefs 游戏存档
- 编程中最没用的东西是源代码,最有用的东西是算法和数据结构。
- php实现排序算法(一) 冒泡排序 快速排序
- gdb调试工具的使用
- axure RP
- Shader toy (顺手写两个Gyro)(纯代码写3D)
- PlayerPrefs学习
- 自己写的串口缓冲区
- Axure入门设计——模糊设计(步骤)
- 2015-07-23
- !codeforces 399C Cards-数论&贪心-(暴力枚举)
- 前端请求跨域问题
- mac ocx,android,android studio相关
- 一个关于c++数值转换的小程序的思考
- CentOS-7磁盘扩容之殇