void DrawChangeGUI(int WindowID) { //Size GUI.Label(new Rect(10, 20, 200, 20), "Choose New Size"); string difCols = ""; if (_changeNewNumCols > _boardScript.GetNumberOfColumns()) { difCols += "+"; } difCols += (_changeNewNumCols - _boardScript.GetNumberOfColumns()); GUI.Label(new Rect(10, 40, 100, 20), "Cols (" + difCols + "=" + _changeNewNumCols + "):"); _changeNewNumCols = ToMultipleOfFour(GUI.HorizontalSlider(new Rect(105, 45, 100, 20), _changeNewNumCols, _minSize, _maxSize)); string difRows = ""; if (_changeNewNumCols > _boardScript.GetNumberOfRows()) { difRows += "+"; } difRows += _changeNewNumRows - _boardScript.GetNumberOfRows(); GUI.Label(new Rect(10, 60, 100, 20), "Rows (" + difRows + "=" + _changeNewNumRows + "):"); _changeNewNumRows = ToMultipleOfFour(GUI.HorizontalSlider(new Rect(105, 65, 100, 20), _changeNewNumRows, _minSize, _maxSize)); //Show change type selection GUI.Label(new Rect(10, 90, 200, 20), "Select Type"); _changeTypeEntry = GUI.SelectionGrid(new Rect(10, 110, 200, 80), _changeTypeEntry, TileTypes.TerrainGUIContentList, 3); _changeType = TileTypes.GetTerrainTileInfo(_changeTypeEntry); //Show change position selection GUI.Label(new Rect(10, 200, 200, 20), "Choose direction to expand to"); _changePositionEntry = GUI.SelectionGrid(new Rect(10, 220, 100, 80), _changePositionEntry, _changePositionGUIContent, 3); //Show change button if (GUI.Button(new Rect(10, 320, 200, 40), "Change !")) { ChangeBoardSize(_changeNewNumCols, _changeNewNumRows, _changePositionEntry, _changeType); } DrawGUIWindowCloseButton(ref _drawChangeWindow); GUI.DragWindow(new Rect(0, 0, 10000, 20)); }
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; }