zoukankan      html  css  js  c++  java
  • unity文件 PlayerPrefs.SetInt 保存 And PlayerPrefs.GetInt读取

    unity文件保存读取PlayerPrefs.SetInt   And  PlayerPrefs.GetInt

    using UnityEngine;

    using System.Collections;

    using UnityEngine.UI;

    using UnityEngine.SceneManagement;

    using Enums;

    //定义类管理时间静态变量

    public class global_Mgr

    {

        //定义初始时间

        public static int GoodTime01 = 366;

        //公共静态方法、参数string str, int  CurrentTime

        public static void CurrentTimes(string str, int  CurrentTime)

        {       

                      //判断执行

            switch (str)

            {

                case "Level1":

                    {

                        if (CurrentTime < GoodTime01)

                        {

                            GoodTime01 = CurrentTime;

                        }

                                              //保存最佳时间数据

                        PlayerPrefs.SetInt("GoodTimeInt01", GoodTime01);

                    }

                    break;

                default:  Debug.Log("error");

                    break;

            }

        }

    }

    using System.Collections;

    using UnityEngine;

    //playercontrol控制到达的时间

    public class playercontrol : MonoBehaviour

    {

        //场景名称

        public GameObject Levels=Level01;

        //定义初始时间

        private float times=0;

        //时间累加

        private void Update()

        {

            times += Time.deltaTime;

        }

        //碰撞触发时结束、记录时间 

        public void OnTriggerEnter(Collider other)

        {

            //触发物体

            if (other.name.Equals("Endpoint"))

            {

                int timess = (int)times;

                         //调用global_Mgr中方法

                global_Mgr.CurrentTimes(Levels.name, timess);

            }

        }

    }

    using System.Collections;

    using UnityEngine.SceneManagement;

    using UnityEngine;

    //主场景

    public class MainMenuScene : MonoBehaviour

    {

        //场景运行的时候读取时间

        public void Awake()

        {

             global_Mgr.GoodTime01 = PlayerPrefs.GetInt("GoodTimeInt01");

        }

    }

    注:unity文件 PlayerPrefs保存 And  PlayerPrefs读取、用于string、int、float类型,存取数据可在系统regedit注册表编辑器中进行删除...

    支持个人观看使用,如商用或转载,请告知! -----萧朗(QQ:453929789 Email:xiaolang_xl@sina.com)
  • 相关阅读:
    Phone List(字典树)
    Dating with girls(1)(二分+map+set)
    Color the ball(树状数组+线段树+二分)
    python模块导入总结
    Python爬虫之定时抢购淘宝商品
    Celery多队列配置
    python垃圾回收机制
    python变量、对象和引用你真的明白了吗
    使用 supervisor 管理 Celery 服务
    Supervisor的作用与配置
  • 原文地址:https://www.cnblogs.com/XiaoLang0/p/9683153.html
Copyright © 2011-2022 走看看