/// <summary> /// Mouse click and point logic /// </summary> private void MouseHandler() { if (Input.GetMouseButtonDown(0)) { // create raycast if hitted board assign mouse coordinate RaycastHit hit; if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 25.0f, LayerMask.GetMask("Board"))) { mouseOver.x = (int)hit.point.x - boardofset.x; mouseOver.y = (int)hit.point.z - boardofset.z; } // create raycast if hitted Piece test color of piece and add reference it with holder if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 25.0f)) { GameObject hitted = hit.transform.gameObject; if (hitted.tag == "Piece") { if (gm.GetAccualPlayer() == GameMenager.Player.One && hitted.GetComponent <Piece>().isWHite == true) { holder = hitted; } else if (gm.GetAccualPlayer() == GameMenager.Player.Two && hitted.GetComponent <Piece>().isWHite == false) { holder = hitted; } else { holder = null; } } // if secound mouse click hitted field test atack and move conditions else if (holder != null && hit.transform.gameObject.tag == "Field") { if (ValidMove(holder.transform.gameObject.GetComponent <Piece>(), hit.transform.gameObject.GetComponent <Piece>())) { holder.transform.position = hit.transform.position; gm.ChangePlayer(); } if (ValidAtack(holder.transform.gameObject.GetComponent <Piece>(), hit.transform.gameObject.GetComponent <Piece>())) { holder.transform.position = hit.transform.position; } holder.transform.gameObject.GetComponent <Piece>().createQueen(); } } } }