Unity3d 当前上下文中不存在Unity PlayerPrefs

Unity3d 当前上下文中不存在Unity PlayerPrefs,unity3d,save,settings,Unity3d,Save,Settings,我在Unity 4.6中使用PlayerRefs时出错。我不断收到错误消息,说当前上下文中不存在PlayerPrefs。在MonoDevelop中,当我将鼠标指针悬停在PlayerPrefs语句上时,会收到相同的消息。任何建议都将不胜感激。也许你不在真实的环境中意味着不在从单一行为扩展而来的类中 所需的代码应如下所示: using System.Collections; using System.Collections.Generic; using UnityEngine; public cl

我在Unity 4.6中使用PlayerRefs时出错。我不断收到错误消息,说当前上下文中不存在PlayerPrefs。在MonoDevelop中,当我将鼠标指针悬停在PlayerPrefs语句上时,会收到相同的消息。任何建议都将不胜感激。

也许你不在真实的环境中意味着不在从单一行为扩展而来的类中

所需的代码应如下所示:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class KiaStart : MonoBehaviour
{
    // you can use PlayerPrefs here!...

    void Start()
    {
        
    }


    void Update()
    {
        
    }
}


如果您将整个代码添加到问题中会更好。不是我的回答。我之前试过这么做,但是评论链接不在页面上。事实证明,Unity3d处于某种奇怪的状态。我把它关闭,然后重新打开,问题就消失了。不过我以前见过。是的,有时候Unity3d会崩溃并导致奇怪的错误。但它是固定的,你重新打开它。注释可能是隐藏的,因为编辑您自己的问题并在其中添加代码是更好的做法。在注释中,布局变得混乱。