I have been using Unity for a little while and I am quite far through my game.
I have been Building and Testing my game without a problem for some time now.
But yesterday I attempted to Build my game as a Flash.swf file,
I started Building and it went 3/4 the way through then suddenly quit and I had ‘Game-Breaking’ compiler errors to do with my scripts.
I suddenly had the error:
"BCE0019: ‘enabled’ is not a member of ‘UnityEngine.Component’. "
My scripts are Javascripts and ‘enabled’ always worked as I have it on many scripts.
My main script is:
function Update () {
if(Input.GetKey("escape")) {
//pause the game
Time.timeScale = 0;
//show the pause menu
var script3 = GetComponent("PauseMenuScript");
script3.enabled = true;
//disable the cursor hiding script
var script4 = GetComponent("HideCursorScript");
script4.enabled = false;
//Mouse Look
GetComponent("MouseLook").enabled = false;
//Ambience
GetComponent("AudioSource").enabled = false;
}
}
Please use code tags when posting code. As for the problem, never use strings in GetComponent; that makes it return Component instead of the correct type. (For that matter, don’t use strings in GetKey either; use the KeyCode enum. Strings are problematic and should be avoided if there’s an alternative.)
I have a similar problem. I have an entire, perfectly working compiling Unity project that runs in Desktop mode great. I want to see if I can make a Flash version of it. When I switch to the FlashPlayer mode I get TONS of compiler errors. Many of them are BCE0019 on GetComponet(“SomeScript”). I did use a lot of string literals, but when I change them to GetComponent(SomeScript) I get BCE0005 "Unknown Identifier: ‘SomeScript’. The weird thing is those scripts are in my Standard Assets folder, they’re on all the necessary GameObjects, and this all works perfectly in desktop mode. I have errors on every GetComponent(“SomeScript”) that’s in my script(s).
It’s been a while since I touched Unity Flash, but as I recall it requires scripts to be strictly typed, which is also a requirement for iOS. With a desktop build target, adding #pragma strict to the top of a script will also enforce the script to be strictly typed and generate those same warnings. Once that is in force and you get an error that ‘enabled’ is not in ‘Component’ you should go straight to the Scripting Reference and confirm that indeed, the page for GameObject says that GetComponent returns Component and the page for Component does not list an ‘enabled’ variable. But ‘enabled’ is defined in Behaviour, which is a subclass of Component and is inherited by all Components that you can enable/disable (like Lights), incluiding MonoBehavior and thus all scripts. The solution is to use the generic version of GetComponent as Eric mentioned, described here: