- Home /
parsing error on c# do not destroy code
I keep getting a 'parsing error' on line one of this code and I was wondering if anyone has any idea's what is wrong with it. (I am a big noob when it comes to coding)
private static var instance:MyUnitySingleton; public static function GetInstance() : MyUnitySingleton { return instance; }
function Awake() { if (instance != null && instance != this) { Destroy(this.gameObject); return; } else { instance = this; } DontDestroyOnLoad(this.gameObject); }
I found the code on another unity answers page here
Answer by Cyclops · May 21, 2010 at 02:16 PM
If you read the post closely, you'll see he says:
"(note that this must be in a file called "MyUnitySingleton" - or, in other words: replace any occurrence of "MyUnitySingleton" with the filename of your script)"
Basically - the name of the Variable (currently MyUnitySingleton) must match the name of the Javascript File - which should be MyUnitySingleton. js. I'm guessing it isn't, which is causing the error.
So you need to make sure the file has the correct name. Alternately, you can rename the Class to match your filename.
Your answer
Follow this Question
Related Questions
Script Errors with C# 1 Answer
Errors CS1525 and CS8025.... 1 Answer
c# parsing error Help please and the error is at where it says public string Name 1 Answer
CS8025 error 1 Answer
CS8025 Parsing error 3 Answers