gameObject active problem

I am no luck with activating the gameObject. Can anyone give me a hand?
Here is my code:

function Start()
{
gameObject.Find(“16”).active = false;
}
function Update()
{
if (lock == 1)
{

gameObject.Find(“16”).active = true;
transform.Find(“16”).position =Vector3( Random.Range(-0.44, 0.44),Random.Range(-0.44, 0.47),0.6);

lock = 0;
}

}

then i get this in Console

NullReferenceException
blackHole.Update () (at Assets/iPhone Standard Assets/Scripts/blackHole.js:48)

You can’t use Find on inactive game objects.

–Eric

Yeah that one got me a while back too :stuck_out_tongue:

You can store the GameObject in a variable first then you can activate and deactivate it at any time.

Do something like this:

private var 16_obj : GameObject;

function Start()
{
   16_obj = GameObject.Find("16");
   16_obj.active = false
}

function Update()
{
   if (lock == 1)
   {
      16_obj.active = true;
      16_obj.transform.position = Vector3( Random.Range(-0.44, 0.44),Random.Range(-0.44, 0.47),0.6);
      lock = 0;
   }
}

Untested Code.