- Home /
enable disabled GameObjects
Hello. I am making a racing game and I need now some help. I want to enable my car if I press a button, and than I should drive. But I dont know why my script isnt working. What is wrong with it? Here is the Script:
var car = GameObject.Find("Car Audi R8 2006 N250211");
var came : GameObject;
function Update () { }
function OnGUI (){
GUI.Box(Rect(100,100,600,400),"");
if(GUI.Button(Rect(120,450,100,20),"AudiR8")){
car.enabled = true;
came.enabled = false;
}
}
Can anyone help me pls? How can I enable disabled gameobjects?
Answer by Statement · Jan 08, 2012 at 10:08 PM
You can't find your game object with GameObject.Find. "This function only returns active gameobjects."
What you probably should do is set the reference via the inspector.
var car : GameObject; // Just set the reference via the inspector
var came : GameObject;
function OnGUI() {
GUI.Box(Rect(100,100,600,400), "");
if (GUI.Button(Rect(120,450,100,20),"AudiR8")) {
car.active = true;
came.active = false;
}
}
Your answer
Follow this Question
Related Questions
How can I make code work on a disabled object 1 Answer
What is the best way to manage gameobjects in a scene to conserve memory? 0 Answers
How to activate a GameObject from another scene? 1 Answer
UI Text not displaying for some game objects when Player is within distance of the object 0 Answers
Scripting error 1 Answer