How to check if gameObject existed in the scene?

Hi. I want to create a winning condition. Destroying all the Bricks, then display a button of replay or next. But I don't know how to check if the Brick is completely destroyed in the scene.

function OnMouseDown (){
    Application.LoadLevel (0);
} 

function Start (){
    Screen.showCursor = false;
    this.gameObject.active = false;
}

function Update (){
    if (gameObject.Find ("Brick(Clone)") ==0){
        Screen.showCursor = true;
        this.gameObject.active = true;
    }
}

1 Answer

1

Instead of

 if (gameObject.Find ("Brick(Clone)") ==0)

you should write

  if (GameObject.Find("Brick(Clone)")) 

But using GameObject.Find in Update is not a goo idea. You should check it every time a brick destroys .

also GameObject.Find() != null on the if statement works

Yes. I read from Scripting Reference about using GameObject.Find in Update can cause slow performance. So what kind of code should I use?

As I mentioned, you should call the code every time a brick destroys.