If i click an gameobject it will destroy then it will load a new scene.

let say i have 3 different objects (cubes). if i click one of them it will destroy. now im having a trouble writing a script when the 3 objects is destroy it will load a new scene. i have this code(javascript)

var name : string;

function Start () {

}

function Update () {

}

function OnGUI(){

GUI.Label(new Rect (0,0,100,50), name);

}

function OnMouseDown(){

Destroy(gameObject);

}

i did search for some relevant to this code. i tried to connect it but i cant. can anyone help me? any answer is very much appreciated. thank you in advance.

An easy way to solve this problem is to put a tag on all of your blocks. If you don’t understand tagging, look up Tag Manager in Unity manual. So say all your blocks had the tag ‘Block’. You could then write your OnMosueDown() to be:

function OnMouseDown(){
    var remaining : int = GameObject.FindGameObjectsWithTag("Box").Length;
    if (remaining <= 1) {
        Application.LoadLevel("SomeLevel");
    }
    else {
        Destroy(gameObject);
    }
}