I wanted to use the following code:
credits = GameObject.Find("CreditsButton");
credits.active = false;
to activate an inactive object, but then I discovered that GameObject.Find only works on active objects. How can I reference an inactive object?
I assume you mean “credits.active = true” to activate it. You can assign the object using the inspector:
var credits : GameObject;
…outside any function, and then drag’n’drop. Or you can keep the object active and turn it off at startup, and keep the reference around for later:
private var credits : GameObject;
function Start() {
credits = GameObject.Find("CreditsButton");
credits.active = false;
}
function TurnOnCredits() {
credits.active = true;
}
–Eric
I found another way to do this using the Find function. Make an active empty game object the parent of the gameObject you need to have deactive. Put your script code on the parent object. Now when you run your script call gameObject.SetActiveRecursively(true). Now your child is active just in time to do something.
function Activate() {
gameObject.SetActiveRecursively(true); // activates the children
// do interesting stuff here
}
It would still be nice though if we could find inactive objects like this post suggests.
http://forum.unity3d.com/viewtopic.php?t=6073
1 Like