Ejemplo n.º 1
0
 void OnMouseDown()
 {
     if (Input.GetMouseButtonDown(0) && main.SpaceSelectable)
     {
         bool spaceFound = false;
         int  i = 0, j = 0;
         for (i = 0; i < 8 && !spaceFound; i++)
         {
             for (j = 0; j < 8 && !spaceFound; j++)
             {
                 if (main.Spaces[i, j].Equals(gameObject))
                 {
                     spaceFound = true;
                 }
             }
         }
         if (main.P1Turn)
         {
             main.Player1.Move(main.selectedPiece, new int[] { --i, --j });
         }
         else
         {
             main.Player2.Move(main.selectedPiece, new int[] { --i, --j });
         }
         Target = gameObject.transform.position;
         if (main.P1Turn)
         {
             if (main.Player1.GetPieceType(main.Player1.GetPiecePosition(main.selectedPiece)).Equals("PAWN"))
             {
                 if (Target.z == 3.5f)
                 {
                     pawnAtEnd = true;
                 }
             }
         }
         else
         {
             if (main.Player2.GetPieceType(main.Player2.GetPiecePosition(main.selectedPiece)).Equals("PAWN"))
             {
                 if (Target.z == -3.5f)
                 {
                     pawnAtEnd = true;
                 }
             }
         }
         main.pieceSelectable = false;
         Target.y             = main.selectedPiece.transform.position.y;
         pieceRB = main.selectedPiece.GetComponent <Rigidbody>();
         main.CheckPieceTake(Target);
         MeshRenderer renderer = main.selectedPiece.transform.GetChild(0).GetComponent <MeshRenderer>();
         renderer.material = main.previousColor;
         main.Move(pieceRB, main.selectedPiece, Target);
         main.previousSelection = null;
     }
 }