This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers.
ERROR: BCE0019: 'enabled' is not a member of 'UnityEngine.GameObject'.
Ok, So in my game the main character has to use matches to light a fire. Here is my script:
var batterySound : AudioClip;
private static var batteryPower : float = 10;
var Matches : GameObject;
var Fire : GameObject;
private var hasPlayed = false;
function Start()
{
gameObject.enabled = false;
}
function OnTriggerEnter (c : Collider)
{
buttonInRange = true;
}
function OnTriggerExit (c : Collider)
{
buttonInRange = false;
}
function OnGUI ()
{
if (buttonInRange == true)
{
if (Matches == false)
{
GUI.Label (Rect (Screen.width/2-50, Screen.height/2-55, 120, 50), "Use matches");
}
}
}
function Update ()
{
if (buttonInRange == true)
{
if (Input.GetKeyDown ("e"))
{
if(!hasPlayed)
{
AudioSource.PlayClipAtPoint(batterySound, transform.position);
gameObject.enabled = false;
hasPlayed = true;
}
}
}
}
It all works fine except when I go to play it, I get the error Assets/FireStart.js(46,44): BCE0019: 'enabled' is not a member of 'UnityEngine.GameObject'. in lines 15 and 55... when I try to get rid of this error, the game plays but the fire is automatically on. Just to recap, what I want is an empty fireplace and the character collects matches (this collection part works fine) and then when the player gets close enough to the fireplace it displays "use matches" (which also works perfectly) and when the player presses "E", the fire will be lit (DOES NOT WORK).... I have no idea what is wrong.... Thanks
FAQ :
Some reasons for getting a post rejected:
Posting about a specific compiling error or NullReferenceException: there is a myriad of these questions with answers already, have a look at those posts to get hints on what could possibly be your issue. Also, take a look at the Unity's support website, many errors and how to solve them are described here
Answer by doublemax · Oct 16, 2016 at 04:09 PM
Compilers usually don't lie and when you check the documentation for GameObject, you'll see that it doesn't have a public variable "enabled".
Try gameObject.SetActive(false);
However, if you'd call SetActive(false) in Start(), Update() would never get called. So i'm not sure if that's what you actually want to do.
It worked but you're right, update no longer works.... It's definitely a start though, I'll just fiddle with it for a bit
Answer by Lilius · Oct 16, 2016 at 04:10 PM
Try this: gameobject.SetActive(true); gameobject.SetActive(false);
This is not what he meant.
EX: If an object attached to a camera is set from true to false, and the player walks around and then sets the object to true, the object attached to the camera will not be positioned in front of the camera.
Thats excatly what he meant, and that is excatly how game objects are enabled/disabled. Same answer is also in accepted answer. JavaScript is not supported anymore and this is two years old question.