- Home /
gameObject.active Find
OK or a problem I'm trying to activate a GameObject via tag or name, called from a prefab that will appear on the scene later the problem 'that can not be connected to a GameObject in the scene prefab newly instantiated otherwise I would have already solved:
var target: GameObject;
Explosion.SetActive (true);
O then tried countless other solutions such as:
function Start () {
var Explosion = GameObject.Find ("On");
if (Explosion.tag == "on") {
Explosion.Find ("on".) active = true;
}
or
street children
function Start () {
var Explosion = transform.Find ("On1 / On2");
Explosion.Find ("object"). active = true;
}
or
var Explosion = GameObject.FindGameObjectsWithTag ("on");
or
function Start () {
Explosion = GameObject.Find ("on");
if (other.name == "on") {
Explosion.SetActive (true);
}
}
of course you always receive this error:
""NullReferenceException: Object reference not set to an instance of an object"" ps. obviously none of these and countless other script-based "Find" works to activate a GameObject "Find "the directory can only disable a GameObject in the scene
Anybody have any idea, Solution To resolve this problem Thanks
This question is almost impossible to read. Please use the code block when you're posing code.
Your description of the problem is also almost unintelligible. From what I gather, you cannot find a GameObject at some point during runtime, is this correct?
I apologize for my English or created this script to activate a GameObject in the scene:
var Explosion : GameObject;
Explosion.SetActive (true);
I put this script to a prefab,This prefab will be called in scene after an event,when this prefab will make its appearance in the game scene, the script should activate a GameObject named Explosion.
But The problem is this:
the prefab you can not connect the GameObject that is in the gambling scene called "Explosion" therefore I can not use this script, Another way I have to use to get this, using just FindWithTag Why you can not manually insert GameObject name "Explosion" in the script of prefab
But FindWithtag can not activate GameObject, But Only Deactivate gameObject who are already active in the scene.
This Script:
var Explosion = GameObject.FindGameObjectsWithTag ("on");
Explosion.SetActive (false);
Not true only Deactive Find Only
Deactive GameObiect
I hope to be more understandable
Let me ask you this: is Explosion a child of another object that is disabled (during runtime)?
Answer by Bluntweapon · Sep 14, 2014 at 04:21 AM
var target = GameObject.FindGameObjectsWithTag ("on");
Should work if the object is indeed tagged "on".
Otherwise when you instantiate a GameObject, unless you specifically set its name, it will always be named "prefabName (clone)". Try searching for that instead.