切换播放器首选项以在统一文本字段中显示

时间:2016-11-17 19:23:10

标签: c# unity3d unity5

我在文本字段中显示来自playerprefs的字符串时遇到一些麻烦

public void ActiveToggle ()
{
    if (isNone.isOn)
    {
        PlayerPrefs.SetString("Offer_schedule","None");
        PlayerPrefs.Save();
        Debug.Log("Offer_schedule".ToString());
    } else if (isDaily.isOn) {
        PlayerPrefs.SetString("Offer_schedule","Daily");
        PlayerPrefs.Save();
        Debug.Log("Offer_schedule".ToString());
    } else if (isWeekly.isOn) {
        PlayerPrefs.SetString("Offer_schedule","Weekly");
        PlayerPrefs.Save();
        Debug.Log("Offer_schedule".ToString());
    }
}

Offer_schedule =PlayerPrefs.GetString("Offer_schedule");

我将播放器优惠计划保存为基于所选切换的字符串 offerschedule.text = PlayerPrefs.GetString(“Offer_schedule”); 我无法在文本字段中显示字符串

1 个答案:

答案 0 :(得分:0)

你的错误存在于Debug.Log("Offer_schedule".ToString());

在这里,您将String literal转换为字符串。这意味着您只是显示文字字符串"Offer_schedule"

如果您想要Debug.Log()实际PlayerPrefs值,您将获得A:

// Debug the result from the GetString directly
Debug.Log(PlayerPrefs.GetString("Offer_schedule"));

或在您上面的代码中尝试使用B:

// Store our value in in a variable
string Offer_schedule = PlayerPrefs.GetString("Offer_schedule");
// Now display our variable
Debug.Log(Offer_schedule);

在第二个例子中看看我们如何使用",使其成为对变量的调用,而不是写一个文字。