码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2018-09-20 21:23:15      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:manage   equal   evel   unity   删除   类型   系统   编辑器   date()   

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注册表编辑器中进行删除...

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

标签:manage   equal   evel   unity   删除   类型   系统   编辑器   date()   

原文地址:https://www.cnblogs.com/XiaoLang0/p/9683153.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!