checking n number of Prefabs are clicked or not

Hii, everybody...

I am trying to solve one problem from last few days, but didnt get successful to solve it completly.

i want to check that user has clicked on all cubes or not. if he clicked on all prefabs( cubes)in the scene then only nxt scene will apperared.

Now for this things i am using raycast concept to check our cube is hitted or not.

Just look at my following code.

function Update ()
{
    if(Input.GetMouseButtonDown(0))
    {
      var hit:RaycastHit;
      var ray = Camera.main.ScreenPointToRay (Input.mousePosition);

      if (Physics.Raycast (ray,hit,100.0)) { 
        Debug.Log("clicked");
        if(hit.transform.name=="box1") //here box1 is my prefab(cube) name
        {
          isTouchCube1=true;
        }
        if(hit.transform.name=="box2") //here box2 is my prefab(cube) name
        {
          isTouchCube2=true;
        }

        if(isTouchCube1 &&isTouchCube2)
        {
          Application.LoadLevel ("oops_01");
        }

      }
   }
}

my code simply gives the idea what i'm trying to do ,

So anybody is there to solve this issue ?

Or if u r having any other method code to solve this issue the also helpful for me.

Also one imp question where should i need to attach this script? currently i'm attaching to all cubes for

whom i'm checking they r hitted or not.

If there is problem with understanding of my question then also plz tel me.

1 Answer

1

This script could go on any one game object, does not have to be on all cubes.

What's the issue here? This looks like it would work. If you mean to expand this to many cubes, and the conditions would get hairy, you could use an array instead of individual variables to track these. Or you could put the click detection on each object (just click detect, which could also be OnMouseDown), and have that SendMessage to a 'master' script that would tabulate what's been hit and look for a complete set.

ok, but can we call another script using SendMessage.?? as we used it like this way SendMessage ("ApplyDamage"); // we r calling a function here so just tel me , is following way should be good for to do it. 1. I will create & attach a detection script for each cube to check that it is clicked or not. 2.then in that all scripts i'll call to another script. 3. and according to u in master script i'll check that number of cubes are clicked or not?

Yes and yes. Actually SendMessage is really good for calling other scripts as it gets around the JScript/C# slight-incompatibility issue. Or you can call the function directly in the master script by getting the G.O. with that component on it, and GetComponent. Six of one, half-dozen the other.