找不到类型或命名空间名称 'Scene'

The type or namespace name 'Scene' could not be found

第一次在这里提问。我最近才开始用UNITY 3D编程,所以我的问题可能很常见,但我真的找不到任何答案。

我正在观看 YouTube 上的教程并复制相同的代码。一切都和视频中一样,但是作者没有任何问题,而我有,我检查了10次代码,这是问题标题中的问题。

在此先感谢您的支持!

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


public class GameManager : MonoBehaviour
{
    public static GameManager instance;
    private void Awake()
    {
        instance = this;
    }
    // Resourses 
    public List<Sprite> playerSprites;
    public List<Sprite> weaponSprites;
    public List<int> weaponPrices;
    public List<int> xpTable;

    // References

    public Player player;

    //private weapon weapon...

    //Logic
    public int pesos;
    public int experience;

    // SaveState
    /*
     * INT preferedSkin
     * INT pesos
     * INT experience
     * INT weaponLevel
     *
     */
    public void SaveState()
    {
        string s = "";
        
        s += "0" + "|";
        s += pesos.ToString() + "|";
        s += experience.ToString() + "|";
        s += "0";

        PlayerPrefs.SetString("SaveState", s);
    }
    public void LoadState(Scene s, LoadSceneMode mode)
    {
        if(!PlayerPrefs.HasKey("SaveState"))
        {
            return;
        }
        
        string[] data = PlayerPrefs.GetString("SaveState").Split('|');
        
        // Change player skin
        pesos = int.Parse(data[1]);
        experience = int.Parse(data[2]);
        // Change the weapon Level
        
        Debug.Log("LoadState");
    }
}

Scene 是 SceneManagment 命名空间的一部分。尝试添加:

using UnityEngine.SceneManagement;

来源:https://docs.unity3d.com/ScriptReference/SceneManagement.Scene.html

您缺少包参考。 google 搜索告诉我 Scene class 是在 UnityEngine.CoreModule 中实现的,因此请尝试将其添加到顶部:

using UnityEngine.CoreModule

如果您正在使用 Visual Studio,您可以将光标放在 Scene 上并点击 crtl + . 以获得建议。

您可以这样使用“完全限定的命名空间”

public void LoadState(UnityEngine.SceneManagement.Scene s, LoadSceneMode mode)

或通过在顶部包含 using UnityEngine.SceneManagement; 来导入库,您可以通过按住 CTRL 并按 (.) 在 Visual Studio 中轻松访问它,这通常是第一个选项,但首先要确保你的光标停留在代码的错误部分