void MoveAround() { //Move around float hor = Input.GetAxis("Horizontal"); float ver = Input.GetAxis("Vertical"); if (hor != 0 || ver != 0) { Vector3 right = transform.right * hor; Vector3 forward = transform.up * ver; Vector3 total = right + forward; float lengthTotal = total.magnitude; total.y = 0; total.Normalize(); total *= lengthTotal; total *= _moveSpeed; total *= Time.deltaTime; transform.Translate(total, Space.World); } //newPos is current pos Vector3 newPos = transform.position; //Cal max pos int cols = _board.GetNumberOfColumns(); int rows = _board.GetNumberOfRows(); Vector3 maxPos = _board.GetWorldPosition(cols - 1, rows - 1); //Calc min pos Vector3 minPos = _board.GetWorldPosition(0, 0); //Make sure newPos isn't bigger or smaller than max or min pos newPos.x = Mathf.Max(minPos.x, newPos.x); newPos.z = Mathf.Max(minPos.z, newPos.z); newPos.x = Mathf.Min(maxPos.x, newPos.x); newPos.z = Mathf.Min(maxPos.z, newPos.z); newPos.y = 0; transform.position = newPos; }
private BasicTile CreateNewTile(Object tile, TeamsInfo.Colour colour, int col, int row) { //Create the new tile, give it proper name and position. GameObject newTileGO = Instantiate(tile) as GameObject; BasicTile newTile = newTileGO.GetComponent("BasicTile") as BasicTile; newTile.transform.position = _boardScript.GetWorldPosition(col, row); newTile.transform.parent = _boardScript.gameObject.transform; newTile.gameObject.name = "Tile(" + col + "," + row + ")" + newTile.tag; newTile.Collumn = col; newTile.Row = row; newTile.Colour = colour; return(newTile); }