I am following a beginner tutorial on making a file manager and getting an error when trying to make an instance.
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;
}
}
}
The error is :
Expression denotes a type, where a variable, value or method group was expected
The argument to the GameObject constructor must be a variable, or one of those other things. In particular, it must represent a value, that is, an instance of a type. You have supplied the name of a type.
It is as though you wanted to open a file called C:\file.txt, but called Open(string)
instead of Open("C:\file.txt")
.
It might be a good idea to get in the habit of following .NET naming conventions, in which type names start with upper case letters.
Apparently, the tutorial's sample code is incorrect. The GetComponent method requires either a type argument or a 'regular' argument. The sample code supplies neither.