Mahjong Matching game

The following script is intended to be used for matching like tagged objects. I.e. There are six cubes, two of which are red. I want to select one red cube, then the other red cube which will destroy both. If I touch a red cube and then a non red cube, I would like nothing to happen.

The red cubes are labled "Match" while the other cubes are labeled "Othercubes."

Thanks,

Greg

var hit : RaycastHit;
var hitNum = 0;
var firstObjHit : GameObject;
var secondObjHit : GameObject;
var myTransform : Transform;

function Awake() { myTransform = transform; // this objects transform }

function Update () { for (var evt : iPhoneTouch in iPhoneInput.touches) { if (evt.phase == iPhoneTouchPhase.Began) { var ray = camera.main.ScreenPointToRay(evt.position); if (Physics.Raycast(ray, hit, 10) ) {

        //var hitObject : GameObject = hit.transform.gameObject;
          // var hitTransform : Transform = hitObject.transform;
           switch(hitNum) {
           case 0:
              ++hitNum;

              break;

           case 1:

if(firstObjHit.tag.Contains("Match")) == (secondObjHit.tag.Contains("Match"))

//trigger event Destroy( firstObjHit); Destroy( secondObjHit); } hitNum = 0; break; } }}}

You are using firstObjHit and secondObjHit, but I can't see that those variables are assigned anywhere in your code. On case 0 you should do firstObjHit = hit.transform.gameObject. The same on case 1 with secondObjHit.

Thanks for the input, Spree! Still having problems with this. My current script:

var hit : RaycastHit; var hitNum = 0; var firstObjHit : GameObject; var secondObjHit : GameObject; var myTransform : Transform;

function Awake() { myTransform = transform; // this objects transform }

function Update () { for (var evt : iPhoneTouch in iPhoneInput.touches) { if (evt.phase == iPhoneTouchPhase.Began) { var ray = camera.main.ScreenPointToRay(evt.position); if (Physics.Raycast(ray, hit, 10) ) {

` var hitObject : GameObject = hit.transform.gameObject;
var hitTransform : Transform = hitObject.transform;
switch(hitNum) {
case 0:
++hitNum;
firstObjHit = hit.transform.gameObject;
break;

       case 1:
          secondObjHit = hit.transform.gameObject; 

              //trigger event
          Destroy( firstObjHit);
           Destroy( secondObjHit);
          }
          hitNum = 0;
          break;
    } }}}

`