void Update() { readifyLogo.enabled = !nextPlayer; kloudLogo.enabled = nextPlayer; if (Input.GetMouseButtonUp(0)) { RaycastHit raycastHit = new RaycastHit(); bool hit = Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out raycastHit); if (hit) { if (raycastHit.transform.gameObject.CompareTag("IndividualCell")) { moveCounter++; nextPlayer = !nextPlayer; if (moveCounter == 9) { winnerMessage.text = "Draw"; ResetGame(); } GameObject temp = raycastHit.transform.gameObject; var indexToBeAccessed = System.Convert.ToInt32(temp.name); Destroy(temp); //take turns //first player if (nextPlayer) { playerX.name = "X"; squares.SetValue("X", indexToBeAccessed); Instantiate(playerX, temp.transform.position, temp.transform.rotation, game.transform); if (CalculateWinner(squares) != null) { winnerMessage.text = "Readifarian Wins"; fireWorks.SetActive(true); ResetGame(); } } //second player else { playerO.name = "O"; squares.SetValue("O", indexToBeAccessed); Instantiate(playerO, temp.transform.position, temp.transform.rotation, game.transform); if (CalculateWinner(squares) != null) { winnerMessage.text = "Kloudie Wins"; fireWorks.SetActive(true); ResetGame(); } } } } } }
// check for input action (phone touch) private void CheckForInputAction() { if (Input.touchCount > 0) { Touch touch = Input.GetTouch(0); bool bInputAction = true; switch (touch.phase) { case TouchPhase.Began: inputAction = MultiARInterop.InputAction.Click; inputNavCoordinates = Vector3.zero; startInputPos = touch.position; startTimestamp = lastFrameTimestamp; break; case TouchPhase.Moved: case TouchPhase.Stationary: if ((lastFrameTimestamp - startTimestamp) >= 0.25) { inputAction = MultiARInterop.InputAction.Grip; float screenMinDim = Screen.width < Screen.height ? Screen.width : Screen.height; Vector3 mouseRelPos = touch.position - startInputPos; inputNavCoordinates = mouseRelPos / screenMinDim; } break; case TouchPhase.Ended: inputAction = MultiARInterop.InputAction.Release; break; default: bInputAction = false; break; } if (bInputAction) { inputPos = touch.position; inputTimestamp = lastFrameTimestamp; } } else { #if UNITY_EDITOR bool bInputAction = true; if (Input.GetMouseButtonDown(0)) { inputAction = MultiARInterop.InputAction.Click; startInputPos = Input.mousePosition; startTimestamp = lastFrameTimestamp; } else if (Input.GetMouseButton(0)) { if ((lastFrameTimestamp - startTimestamp) >= 0.25) { inputAction = MultiARInterop.InputAction.Grip; //Vector3 screenSize = new Vector3(Screen.width, Screen.height, 0f); float screenMinDim = Screen.width < Screen.height ? Screen.width : Screen.height; Vector3 mouseRelPos = Input.mousePosition - (Vector3)startInputPos; inputNavCoordinates = mouseRelPos / screenMinDim; // new Vector3(mouseRelPos.x / screenSize.x, mouseRelPos.y / screenSize.y, 0f); } } else if (Input.GetMouseButtonUp(0)) { inputAction = MultiARInterop.InputAction.Release; } else { bInputAction = false; } if (bInputAction) { inputPos = Input.mousePosition; inputTimestamp = lastFrameTimestamp; } #endif } }