尝试创建文件管理器的实例时出错

Error when trying to make an instance of a file manager

我正在学习有关制作文件管理器的初学者教程,但在尝试制作实例时遇到错误。

public class fileManager : MonoBehaviour 
{
    private static fileManager instance;    // Instance of the fileManager
    private string path;                    // Holds the application path

    public static fileManager Instance {
        get {
            if (instance == null) {
                instance = new GameObject("fileManager").AddComponent();
            }

            return instance;
        }
    }  
}

错误是:

Expression denotes a type, where a variable, value or method group was expected

我觉得这很可疑:

instance = new GameObject(fileManager).AddComponent();

我猜 GameObject 构造函数需要一个 Type 参数。
尝试更改为:

instance = new GameObject(typeof(fileManager)).AddComponent();

或:

instance = new GameObject(new fileManager()).AddComponent();

GameObject 构造函数的参数必须是一个变量,或者其他变量之一。特别是,它必须表示一个值,即一个类型的实例。您提供了类型的名称。

就好像您想打开一个名为 C:\file.txt 的文件,但名称为 Open(string) 而不是 Open("C:\file.txt")

最好养成遵循 .NET 命名约定的习惯,其中类型名称以大写字母开头。

显然,教程的示例代码不正确。 GetComponent 方法需要类型参数或 'regular' 参数。示例代码均未提供。