- Home /
Getting "UnityEngine.GameObject.enabled' not found error
I am trying to setup a menu that has about 15 options, which will bounce between 4 separate cameras depending on what is selected.
I've tried a few different ideas, and non seemed to work, so went to a simple switch statement, but now getting a ton of errors. (see below)
var camera1 : GameObject;
var camera2 : GameObject;
var camera3 : GameObject;
var camera4 : GameObject;
var CamNum : float = 1; // if the number is one Camera one is enabled , if its 2 Camera two is enabled
var menuInput:int = 0;
function OnMouseDown(){
switch (menuInput) {
case 1:
CamNum = 2;
break;
case 2:
CamNum = 3;
break;
case 3:
CamNum = 2;
break;
case 4:
CamNum = 1;
break;
case 5:
CamNum = 1;
break;
case 6:
CamNum = 1;
break;
case 7:
CamNum = 1;
break;
case 8:
CamNum = 1;
break;
case 9:
CamNum = 1;
break;
case 10:
CamNum = 1;
break;
case 11:
CamNum = 1;
break;
case 12:
CamNum = 1;
break;
case 13:
CamNum = 4;
break;
case 14:
CamNum = 1;
break;
case 15:
CamNum = 1;
break;
}
}
function Update(){
if( CamNum == 1){
camera1.enabled = true;
camera2.enabled = false;
camera3.enabled = false;
camera4.enabled = false;
}
if( CamNum == 2){
camera1.enabled = false;
camera2.enabled = true;
camera3.enabled = false;
camera4.enabled = false;
}
if( CamNum == 3){
camera1.enabled = false;
camera2.enabled = false;
camera3.enabled = true;
camera4.enabled = false;
}
if( CamNum == 4){
camera1.enabled = false;
camera2.enabled = false;
camera3.enabled = false;
camera4.enabled = true;
}
}
Each of the errors points to this line of code.
camera1.enabled = true;
Which is sitting in this block:
if( CamNum == 1){
camera1.enabled = true;
camera2.enabled = false;
camera3.enabled = false;
camera4.enabled = false;
}
I'm not sure why its giving an error like this, some help please... Am I missing something simple?
This is the error from the log:
Boo.Lang.Runtime.DynamicDispatching.PropertyDispatcherFactory.FindExtension (IEnumerable`1 candidates) Boo.Lang.Runtime.DynamicDispatching.PropertyDispatcherFactory.Create (SetOrGet gos) Boo.Lang.Runtime.DynamicDispatching.PropertyDispatcherFactory.CreateSetter () Thanks in advance...MissingFieldException: Field 'UnityEngine.GameObject.enabled' not found.
Answer by whydoidoit · Jul 08, 2012 at 09:30 AM
Define your variables as Camera rather than GameObject - GameObject does not have an enabled property (that is a property of certain components) - it does have an active property but in your case just changing the variable definitions should be what you want.
Excellent no more errors, but unfortunately nothing is happening when i click on any of the menu items either :(
Each menu item is labeled in the hierarchy 1-15 and assigned the $$anonymous$$enuInput to match for each one. (1-15) Box collider is on each of the menu items as well. and not set to "is trigger?"
Never$$anonymous$$d, I figured it out. The Function Update wasn't being called after the selection from the On$$anonymous$$ouseDown function was made. Now works like a charm, thanks for the assist!!!
Your answer
Follow this Question
Related Questions
Making the players head face toward the location of the mouse? 1 Answer
Keep getting the Error: Camera' does not contain a definition for `mainCamera' 2 Answers
Expressions in statements must only be executed for their side-effects. 1 Answer
Javascript literal error: unexpected identifier 1 Answer
UnityEngine.Rect' does not have a visible constructor that matches the.... 2 Answers