Checking detection of gameobject correction

hii, i'm trying to develop one script for detection of cubes.

Below is that script.

script.js

function OnMouseDown ()
{
    Debug.Log("clicked");
    CheckCubes();
}

function CheckCubes()
{
    var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition);
    var mousehit : RaycastHit;        
    if (Physics.Raycast (ray, mousehit) && (mousehit.collider.tag == "OLD_TRY")) 
    {
        mousehit.transform.gameObject.active = false;
    }
}

This script uses raycast concept, and if we click on gameobject ,gameobject disappears.

Now i just need to check that if all gameobjects are hitted(clicked), goes to next scene.

So anybody is having any idea or script, what should i can use to check all gameobjects are hitted?

Thanks,

Any suggestions will be helpful.

Just a little hint: OnMouseDown is not called just when you press the mouse button. It's called when you click on the collider of a GameObject. It's called just on that GameObject so you don't need to raycast. The OnMouseDown event is created by Unity and already uses a raycast internally to find the hitted GO.

That would do the same if every of your GameObjects that should be hitted have this script attached.

function OnMouseDown ()
{
    Debug.Log("clicked");
    gameObject.active = false;
}

In your case it would be the simplest thing to check right after you clicked on a GameObject. Just search for all gameobjects that have this script attached (name: script.js)

function OnMouseDown ()
{
    Debug.Log("clicked");
    gameObject.active = false;

    // check if all objects are disabled
    var allObjects : script[] = Object.FindObjectsOfType(script) as script[];
    var allDeactivated = true;
    for (var current : script in allObjects)
    {
        if (current.gameObject.active)
            allDeactivated = false;
    }
    if (allDeactivated)
    {
        // here we know all are disabled, do what you want
        // eg. Application.LoadLevel("NextLevelName");
    }
}

I thought this question was already answered here?!


You should set cubeCount to a valid number in the Inspector or by counting all GameObjects with tag = "ClickObjects".