Example #1
0
 // Update is called once per frame
 void Update()
 {
     if (SetRect.isTouchDown)
     {
         if (Input.GetAxis("Mouse X") < -0.3)
         {
             //Code for action on mouse moving left
             dir = Direction.LEFT;
             print("Mouse moved left");
         }
         if (Input.GetAxis("Mouse X") > 0.3)
         {
             //Code for action on mouse moving right
             dir = Direction.RIGHT;
             print("Mouse moved right");
         }
         if (Input.GetAxis("Mouse Y") < -0.3)
         {
             //Code for action on mouse moving down
             dir = Direction.DOWN;
             print("Mouse moved down");
         }
         if (Input.GetAxis("Mouse Y") > 0.3)
         {
             //Code for action on mouse moving up
             dir = Direction.UP;
             print("Mouse moved up");
         }
         if (Input.GetAxis("Mouse Y") > -0.3 && Input.GetAxis("Mouse Y") < 0.3 &&
             Input.GetAxis("Mouse X") > -0.3 && Input.GetAxis("Mouse X") < 0.3)
         {
             dir = Direction.NONE;
         }
         print(objBlock.Length);
         for (int i = 0; i < objBlock.Length; i++)
         {
             SetRect tempRect = (SetRect)objBlock[i].GetComponent("SetRect");
             if (tempRect.isTouch)
             {
                 if (dir == Direction.LEFT)
                 {
                     tempRect.isTouch = false;
                     tempObj2         = (TouchEvent)objBlock[i].GetComponent("TouchEvent");
                     if (tempObj2.column != 0)
                     {
                         tempObj2.moveL();
                         arrNum = i;
                         isMove = true;
                         break;
                     }
                 }
                 if (dir == Direction.RIGHT)
                 {
                     tempRect.isTouch = false;
                     tempObj2         = (TouchEvent)objBlock[i].GetComponent("TouchEvent");
                     if (tempObj2.column != num - 1)
                     {
                         tempObj2.moveR();
                         arrNum = i;
                         isMove = true;
                         break;
                     }
                 }
                 if (dir == Direction.UP)
                 {
                     tempRect.isTouch = false;
                     tempObj2         = (TouchEvent)objBlock[i].GetComponent("TouchEvent");
                     if (tempObj2.row != num - 1)
                     {
                         tempObj2.moveU();
                         arrNum = i;
                         isMove = true;
                         break;
                     }
                 }
                 if (dir == Direction.DOWN)
                 {
                     tempRect.isTouch = false;
                     tempObj2         = (TouchEvent)objBlock[i].GetComponent("TouchEvent");
                     if (tempObj2.row != 0)
                     {
                         tempObj2.moveD();
                         arrNum = i;
                         isMove = true;
                         break;
                     }
                 }
             }
         }
         if (isMove)
         {
             for (int j = 0; j < objBlock.Length; j++)
             {
                 if (arrNum != j)
                 {
                     TouchEvent tempEvent = (TouchEvent)objBlock[j].GetComponent("TouchEvent");
                     if (objBlock[j].transform.position == tempObj2.transform.position)
                     {
                         if (dir == Direction.LEFT)
                         {
                             tempEvent.moveR();
                             isMove = false;
                             Match();
                         }
                         if (dir == Direction.RIGHT)
                         {
                             tempEvent.moveL();
                             isMove = false;
                             Match();
                         }
                         if (dir == Direction.UP)
                         {
                             tempEvent.moveD();
                             isMove = false;
                             Match();
                         }
                         if (dir == Direction.DOWN)
                         {
                             tempEvent.moveU();
                             isMove = false;
                             Match();
                         }
                         break;
                     }
                 }
             }
         }
     }
 }