在Unity中,如何判断这是第一次打开游戏? [英] In Unity, how to tell if it's the first time a game is being opened?

查看:151
本文介绍了在Unity中,如何判断这是第一次打开游戏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要运行脚本,

当我第一次在Unity中打开游戏时.

whenever my game in Unity is opened for the first time.

推荐答案

使用PlayerPrefs.检查密钥是否存在.如果密钥不存在,则返回默认值 1 ,这是第一次打开.另外,如果这是第一次打开,请将该键设置为 0 ,这样,如果再也不会返回 1 .因此,任何不是 1 的值都意味着不是是第一次打开.在此示例中,我们可以调用键FIRSTTIMEOPENING.

Use PlayerPrefs. Check if key exist. If the key does not exist, return default value 1 and that is first time opening. Also, If this is first time opening set that key to 0 so that if will never return 1 again. So any value that is not 1 means that it is not the first time opening. In this example we can call the key FIRSTTIMEOPENING.

if (PlayerPrefs.GetInt("FIRSTTIMEOPENING", 1) == 1)
{
    Debug.Log("First Time Opening");

    //Set first time opening to false
    PlayerPrefs.SetInt("FIRSTTIMEOPENING", 0);

    //Do your stuff here

}
else
{
    Debug.Log("NOT First Time Opening");

    //Do your stuff here
}

这篇关于在Unity中,如何判断这是第一次打开游戏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆