private void TapGestureCallback(GestureRecognizer gesture) { if (gesture.State == GestureRecognizerState.Ended && !intro && !shifting) { float touchX = gesture.FocusX; float touchY = gesture.FocusY; Vector2 touchPosition = new Vector2(touchX, touchY); RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(touchPosition); ChessboardController2D currentController = null; foreach (ChessboardController2D chessboardController in chessboardControllers) { if (chessboardController.transform.forward == viewVector) { currentController = chessboardController; } } if (Physics.Raycast(ray, out hit, 1000, 1 << currentController.gameObject.layer)) { Transform objectHit = hit.transform; bool clickedTile = false; while (objectHit != null) { if (objectHit.GetComponent <Tile2D>() != null) { ClickTile(objectHit.GetComponent <Tile2D>().position); clickedTile = true; break; } else { objectHit = objectHit.parent; } } if (!clickedTile) { ClickOffTile(); } } else { ClickOffTile(); } } }
// Update is called once per frame void Update() { if (Input.GetKey(KeyCode.Mouse1) && !EventSystem.current.IsPointerOverGameObject()) { Point4 newAttackedTile = attackedTile; RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); ChessboardController2D currentController = null; foreach (ChessboardController2D chessboardController in chessboardControllers) { if (chessboardController.transform.forward == viewVector) { currentController = chessboardController; } } if (Physics.Raycast(ray, out hit, 1000, 1 << currentController.gameObject.layer)) { Transform objectHit = hit.transform; bool clickedTile = false; while (objectHit != null) { if (objectHit.GetComponent <Tile2D>() != null) { newAttackedTile = objectHit.GetComponent <Tile2D>().position; clickedTile = true; break; } else { objectHit = objectHit.parent; } } if (!clickedTile) { newAttackedTile = Point4.NONE; } } else { newAttackedTile = Point4.NONE; } if (newAttackedTile != attackedTile) { attackedTile = newAttackedTile; UpdateTileHighlights(); } } else { if (attackedTile != Point4.NONE) { attackedTile = Point4.NONE; UpdateTileHighlights(); } } /*if (Input.GetKeyDown(KeyCode.RightArrow)) * { * TryRightTurn(); * } * * if (Input.GetKeyDown(KeyCode.LeftArrow)) * { * TryLeftTurn(); * } * * if (Input.GetKeyDown(KeyCode.UpArrow)) * { * TryUpTurn(); * } * * if (Input.GetKeyDown(KeyCode.DownArrow)) * { * TryDownTurn(); * }*/ /*if (Input.GetKeyDown(KeyCode.Space)) * { * StartCoroutine(RunAI()); * } * * if (Input.GetKeyDown(KeyCode.Backspace)) * { * Undo(); * }*/ }