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?
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");
}
}