// Use this for initialization void Start() { //ends = 2; //rotations = 0; pieceName = "Two Door Hallway"; //Set endsUsed relative to what ends are being used //NOTE- Exact values are not being used because sometimes they do not register exact values (DONT KNOW WHY-TRIED TO FIX FOR HOURS) endsUsed = new bool[4]; if (this.gameObject.transform.eulerAngles.y >= 85 && this.gameObject.transform.eulerAngles.y <= 95) { endsUsed [0] = true; endsUsed [1] = false; endsUsed [2] = true; endsUsed [3] = false; } else { endsUsed [0] = false; endsUsed [1] = true; endsUsed [2] = false; endsUsed [3] = true; } int curRow, curColumn; curRow = InstantiateBlocks.getCurRow(this.gameObject.transform.position); curColumn = InstantiateBlocks.getCurColumn(this.gameObject.transform.position); if (curRow != -1 && curRow != InstantiateBlocks.getRows() && curColumn != -1 && curColumn != InstantiateBlocks.getColumns()) { InstantiateBlocks.getAllBlocks() [curRow, curColumn].GetComponent <Block> ().setEnds(endsUsed [0], endsUsed [1], endsUsed [2], endsUsed [3]); InstantiateBlocks.getAllBlocks() [curRow, curColumn].GetComponent <Block> ().setUsed(true); } }
// Use this for initialization void Start() { blocks = InstantiateBlocks.getAllBlocks(); rows = InstantiateBlocks.getRows(); columns = InstantiateBlocks.getColumns(); curRow = InstantiateBlocks.getCurRow(GetComponentInParent <Block> ().gameObject.transform.position); curColumn = InstantiateBlocks.getCurColumn(GetComponentInParent <Block> ().gameObject.transform.position); }
void Update() { //If the raycast finds an endpiece and the player is close and presses E, set isPlacingPiece to true and begin placing piece if (selectedTarget.tag == "EndPiece" && Vector3.Distance(selectedTarget.transform.position, player.transform.position) < 25) { if (Input.GetKeyDown(KeyCode.E)) { isPlacingPiece = true; checkAvailability(); Debug.Log(selectedTarget.name); selectedTargetName = selectedTarget.name; } } //Raycast in front of player and store object that is hit RaycastHit hit; Ray ray = this.gameObject.GetComponentInChildren <Camera> ().ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, 25)) { selectedTarget = hit.transform.gameObject; } if (isPlacingPiece) { //STOP Player movement and display mouse FPC.enabled = false; Cursor.visible = true; Cursor.lockState = CursorLockMode.None; Time.timeScale = 0; } else { FPC.enabled = true; Cursor.visible = false; Cursor.lockState = CursorLockMode.Locked; Time.timeScale = 1; } //DEBUG PURPOSES-WILL ERROR-C WILL CLEAR MAP SO THAT IT IS NO LONGER SAVED if (Input.GetKeyDown(KeyCode.C)) { for (int x = 0; x < InstantiateBlocks.getRows(); x++) { for (int z = 0; z < InstantiateBlocks.getColumns(); z++) { PlayerPrefs.SetInt(x.ToString() + z.ToString() + "isUsed", 0); PlayerPrefs.SetInt(x.ToString() + z.ToString() + "pieceType", 0); } } } }
Inventory inventory; //Inventory script found on player void Start() { //Set player to the player and all the scripts to the player's scripts player = GameObject.FindGameObjectWithTag("Player"); FPC = player.GetComponent <FirstPersonController> (); inventory = player.GetComponent <Inventory> (); //Instantiate so that we do not get NullReference selectedTarget = this.gameObject; refBlock = this.gameObject; possibilities = new bool[11]; //Set corRoomTextures to the corner textures repeated once //They look like this { "|_", ":-", "-:", "_|", "|_", ":-", "-:", "_|" } corRoomTextures = new Texture2D[8]; threeRoomTextures = new Texture2D[8]; for (int i = 0; i < 8; i++) { if (i < 4) { corRoomTextures [i] = InstantiateBlocks.getTextures() [i + 2]; } else { corRoomTextures [i] = InstantiateBlocks.getTextures() [i - 2]; } } //Set threeRoomTextures to the three room textures repeated once //They look like this { "-:-", "-|", "_|_", "|-","-:-", "-|", "_|_", "|-" } for (int i = 0; i < 8; i++) { if (i < 4) { threeRoomTextures [i] = InstantiateBlocks.getTextures() [i + 6]; } else { threeRoomTextures [i] = InstantiateBlocks.getTextures() [i + 2]; } } roomNum = 0; }
// Use this for initialization void Start() { //ends = 4; //rotations = 0; pieceName = "Four Door Hallway"; //Set endsUsed relative to what ends are being used //NOTE- Exact values are not being used because sometimes they do not register exact values (DONT KNOW WHY-TRIED TO FIX FOR HOURS) endsUsed = new bool[4]; endsUsed [0] = true; endsUsed [1] = true; endsUsed [2] = true; endsUsed [3] = true; int curRow, curColumn; curRow = InstantiateBlocks.getCurRow(this.gameObject.transform.position); curColumn = InstantiateBlocks.getCurColumn(this.gameObject.transform.position); InstantiateBlocks.getAllBlocks() [curRow, curColumn].GetComponent <Block> ().setEnds(endsUsed[0], endsUsed[1], endsUsed[2], endsUsed[3]); InstantiateBlocks.getAllBlocks() [curRow, curColumn].GetComponent <Block> ().setUsed(true); }
void checkAvailability() { int refRow, refColumn; //reference row and column of reference block refRow = InstantiateBlocks.getCurRow(); //refRow to currentRow refColumn = InstantiateBlocks.getCurColumn(); //refColumn to currentColumn GameObject[,] blocks = InstantiateBlocks.getAllBlocks(); //If we are at northend, refrow is one up if (selectedTarget.name.Equals("NorthEnd")) { refRow--; roomNum = 0; } else if (selectedTarget.name.Equals("EastEnd")) { //If we are at northend, refrow is one up refColumn++; roomNum = 3; } else if (selectedTarget.name.Equals("SouthEnd")) { //If we are at southend, refrow is one down refRow++; roomNum = 2; } else if (selectedTarget.name.Equals("WestEnd")) { //If we are at westend, refcol is one left refColumn--; roomNum = 1; } refBlock = blocks [refRow, refColumn]; possibilities = InstantiateBlocks.checkAvailability(refRow, refColumn); //Set possibilities to available possibilities for (int i = 0; i < possibilities.Length; i++) { Debug.Log(possibilities [i]); } }
//To be added to when more blocks are available public static bool[] checkAvailability(int refRow, int refColumn) { bool[] possibilities = new bool[11]; //1 - two door room - 0 degrees //East - West //2 - two door room - 90 degrees //North - South //3 - corner room - 0 degrees //North - East //4 - corner room - 90 degrees //East - South //5 - corner room - 180 degrees //South - West //6 - corner room - 270 degrees //North - West //7 - three door room - 0 degrees //East - South - West //8 - three door room - 90 degrees //North - South - West //9 - three door room - 180 degrees //North - East - West //10 - three door room - 270 degrees //North - East - South //11 - four door room //All Directions //Calculate if able to place a certain block heres #region TwoDoorHallway EastWest if (refColumn != InstantiateBlocks.getColumns() - 1 && refColumn != 0) { if (getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().Ends [3] && getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().Ends [1]) { if (refRow != InstantiateBlocks.getRows() - 1 && refRow != 0) { if (getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().getUsed() || getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().getUsed()) { if (getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().getUsed() && getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().getUsed()) { if ((!getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().Ends [0] && !getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().Ends [2])) { possibilities [0] = true; } } else if (getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().getUsed()) { if ((!getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().Ends [0])) { possibilities [0] = true; } } else if (getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().getUsed()) { if ((!getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().Ends [2])) { possibilities [0] = true; } } } else { possibilities [0] = true; } } else if (refRow == InstantiateBlocks.getRows() - 1) { if (getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().Ends [2]) { possibilities [0] = true; } } else { possibilities [0] = true; } } else if (refRow == 0) { if (getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().Ends [0]) { possibilities [0] = true; } } else { possibilities [0] = true; } } } } #endregion #region TwoDoorHallway NorthSouth if (refRow != InstantiateBlocks.getRows() - 1 && refRow != 0) { if (getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().Ends [0] && getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().Ends [2]) { if (refColumn != InstantiateBlocks.getColumns() - 1 && refColumn != 0) { if (getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().getUsed() || getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().getUsed()) { if (getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().getUsed() && getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().getUsed()) { if ((!getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().Ends [3] && !getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().Ends [1])) { possibilities [1] = true; } } else if (getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().getUsed()) { if ((!getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().Ends [3])) { possibilities [1] = true; } } else if (getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().getUsed()) { if ((!getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().Ends [1])) { possibilities [1] = true; } } } else { possibilities [1] = true; } } else if (refColumn == InstantiateBlocks.getColumns() - 1) { if (getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().Ends [1]) { possibilities [1] = true; } } else { possibilities [1] = true; } } else if (refColumn == 0) { if (getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().Ends [3]) { possibilities [1] = true; } } else { possibilities [1] = true; } } } } #endregion #region CornerRoom NorthEast if (refRow != 0 && refColumn != InstantiateBlocks.getColumns() - 1) { if (getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().Ends [2] && getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().Ends [3]) { if (refRow != InstantiateBlocks.getRows() - 1 && refColumn != 0) { if (getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().getUsed() || getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().getUsed()) { if (getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().getUsed() && getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().Ends [0] && !getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().Ends [1]) { possibilities [2] = true; } } else if (getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().Ends [0]) { possibilities [2] = true; } } else if (getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().Ends [1]) { possibilities [2] = true; } } } else { possibilities [2] = true; } } else if (refRow == InstantiateBlocks.getRows() - 1 && refColumn != 0) { if (getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().Ends [1]) { possibilities [2] = true; } } else { possibilities [2] = true; } } else if (refRow != InstantiateBlocks.getRows() - 1 && refColumn == 0) { if (getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().Ends [0]) { possibilities [2] = true; } } else { possibilities [2] = true; } } else { possibilities [2] = true; } } } #endregion #region CornerRoom SouthEast if (refColumn != InstantiateBlocks.getColumns() - 1 && refRow != InstantiateBlocks.getRows() - 1) { if (getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().Ends [0] && getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().Ends [3]) { if (refColumn != 0 && refRow != 0) { if (getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().getUsed() || getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().getUsed()) { if (getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().getUsed() && getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().Ends [2] && !getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().Ends [1]) { possibilities [3] = true; } } else if (getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().Ends [2]) { possibilities [3] = true; } } else if (getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().Ends [1]) { possibilities [3] = true; } } } else { possibilities [3] = true; } } else if (refColumn == 0 && refRow != 0) { if (getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().Ends [2]) { possibilities [3] = true; } } else { possibilities [3] = true; } } else if (refRow == 0 && refColumn != 0) { if (getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().Ends [1]) { possibilities [3] = true; } } else { possibilities [3] = true; } } else { possibilities [3] = true; } } } #endregion #region CornerRoom SouthWest if (refRow != InstantiateBlocks.getRows() - 1 && refColumn != 0) { if (getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().Ends [0] && getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().Ends [1]) { if (refRow != 0 && refColumn != InstantiateBlocks.getColumns() - 1) { if (getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().getUsed() || getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().getUsed()) { if (getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().getUsed() && getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().Ends [2] && !getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().Ends [3]) { possibilities [4] = true; } } else if (getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().Ends [2]) { possibilities [4] = true; } } else if (getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().Ends [3]) { possibilities [4] = true; } } } else { possibilities [4] = true; } } else if (refRow == 0 && refColumn != InstantiateBlocks.getColumns() - 1) { if (getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().Ends [3]) { possibilities [4] = true; } } else { possibilities [4] = true; } } else if (refRow != 0 && refColumn == InstantiateBlocks.getColumns() - 1) { if (getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().Ends [2]) { possibilities [4] = true; } } else { possibilities [4] = true; } } else { possibilities [4] = true; } } } #endregion #region CornerRoom NorthWest if (refColumn != 0 && refRow != 0) { if (getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().Ends [2] && getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().Ends [1]) { if (refColumn != InstantiateBlocks.getColumns() - 1 && refRow != InstantiateBlocks.getRows() - 1) { if (getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().getUsed() || getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().getUsed()) { if (getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().getUsed() && getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().Ends [0] && !getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().Ends [3]) { possibilities [5] = true; } } else if (getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().Ends [0]) { possibilities [5] = true; } } else if (getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().Ends [3]) { possibilities [5] = true; } } } else { possibilities [5] = true; } } else if (refColumn == InstantiateBlocks.getColumns() - 1 && refRow != InstantiateBlocks.getRows() - 1) { if (getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().Ends [0]) { possibilities [5] = true; } } else { possibilities [5] = true; } } else if (refColumn != InstantiateBlocks.getColumns() - 1 && refRow == InstantiateBlocks.getRows() - 1) { if (getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().Ends [3]) { possibilities [5] = true; } } else { possibilities [5] = true; } } else { possibilities [5] = true; } } } #endregion #region ThreeDoorHallway EastSouthWest if (refColumn != 0 && refColumn != InstantiateBlocks.getColumns() - 1 && refRow != InstantiateBlocks.getRows() - 1) { if (getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().Ends [0] && getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().Ends [1] && getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().Ends [3]) { if (refRow != 0) { if (getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().getUsed() && !getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().Ends [2]) { possibilities [6] = true; } else if (!getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().getUsed()) { possibilities [6] = true; } } else { possibilities [6] = true; } } } #endregion #region ThreeDoorHallway NorthSouthWest if (refRow != 0 && refRow != InstantiateBlocks.getRows() - 1 && refColumn != 0) { if (getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().Ends [0] && getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().Ends [1] && getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().Ends [2]) { if (refColumn != InstantiateBlocks.getColumns() - 1) { if (getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().getUsed() && !getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().Ends [3]) { possibilities [7] = true; } else if (!getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().getUsed()) { possibilities [7] = true; } } else { possibilities [7] = true; } } } #endregion #region ThreeDoorHallway NorthEastWest if (refRow != 0 && refColumn != 0 && refColumn != InstantiateBlocks.getColumns() - 1) { if (getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().Ends [3] && getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().Ends [1] && getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().Ends [2]) { if (refRow != InstantiateBlocks.getRows() - 1) { if (getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().getUsed() && !getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().Ends [0]) { possibilities [8] = true; } else if (!getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().getUsed()) { possibilities [8] = true; } } else { possibilities [8] = true; } } } #endregion #region ThreeDoorHallway NorthEastSouth if (refRow != 0 && refRow != InstantiateBlocks.getRows() - 1 && refColumn != InstantiateBlocks.getColumns() - 1) { if (getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().Ends [3] && getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().Ends [0] && getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().Ends [2]) { if (refColumn != 0) { if (getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().getUsed() && !getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().Ends [1]) { possibilities [9] = true; } else if (!getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().getUsed()) { possibilities [9] = true; } } else { possibilities [9] = true; } } } #endregion #region FourDoorHallway if (refRow != 0 && refColumn != InstantiateBlocks.getColumns() - 1 && refRow != InstantiateBlocks.getRows() - 1 && refColumn != 0) { if (getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().Ends [3] && getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().Ends [0] && getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().Ends [2] && getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().Ends [1]) { possibilities [10] = true; } } #endregion return(possibilities); }
void OnGUI() { //SCALE GUI TO SCREEN RESOLUTION float rX, rY; float scale_width, scale_height; scale_width = 1296; scale_height = 729; rX = Screen.width / scale_width; rY = Screen.height / scale_height; GUI.matrix = Matrix4x4.TRS(new Vector3(0, 0, 0), Quaternion.identity, new Vector3(rX, rY, 1)); #region PlacingAPiece //IF PLACING A PIECE IS AVAILABLE AND WE HAVE ENOUGH OF THAT PIECE IN INVENTORY, ALLOW PLAYER TO PLACE PIECE //DISPLAY AMOUNT OF PIECE LEFT UNDERNEATH if (isPlacingPiece) { int x = 50; if (possibilities [0]) { if (GUI.Button(new Rect(x, 550, 100, 50), InstantiateBlocks.getTextures()[1])) { if (Inventory.getAmountOfPiece(0) > 0) { refBlock.GetComponent <Block> ().addPiece(Resources.Load("TwoDoorRoom") as GameObject, new Vector3(0, 0, 0)); for (int i = 0; i < possibilities.Length; i++) { possibilities [i] = false; } isPlacingPiece = false; } } GUI.Label(new Rect(x, 600, 100, 50), "Amount Left: " + Inventory.getAmountOfPiece(0)); x += 100; } if (possibilities [1]) { if (GUI.Button(new Rect(x, 550, 100, 50), InstantiateBlocks.getTextures()[1])) { if (Inventory.getAmountOfPiece(0) > 0) { refBlock.GetComponent <Block> ().addPiece(Resources.Load("TwoDoorRoom") as GameObject, new Vector3(0, 90, 0)); for (int i = 0; i < possibilities.Length; i++) { possibilities [i] = false; } isPlacingPiece = false; } } GUI.Label(new Rect(x, 600, 100, 50), "Amount Left: " + Inventory.getAmountOfPiece(0)); x += 100; } if (possibilities [2]) { if (GUI.Button(new Rect(x, 550, 100, 50), corRoomTextures[roomNum])) { if (Inventory.getAmountOfPiece(1) > 0) { refBlock.GetComponent <Block> ().addPiece(Resources.Load("CornerRoom") as GameObject, new Vector3(0, 0, 0)); for (int i = 0; i < possibilities.Length; i++) { possibilities [i] = false; } isPlacingPiece = false; } } GUI.Label(new Rect(x, 600, 100, 50), "Amount Left: " + Inventory.getAmountOfPiece(1)); x += 100; } if (possibilities [3]) { if (GUI.Button(new Rect(x, 550, 100, 50), corRoomTextures[1 + roomNum])) { if (Inventory.getAmountOfPiece(1) > 0) { refBlock.GetComponent <Block> ().addPiece(Resources.Load("CornerRoom") as GameObject, new Vector3(0, 90, 0)); for (int i = 0; i < possibilities.Length; i++) { possibilities [i] = false; } isPlacingPiece = false; } } GUI.Label(new Rect(x, 600, 100, 50), "Amount Left: " + Inventory.getAmountOfPiece(1)); x += 100; } if (possibilities [4]) { if (GUI.Button(new Rect(x, 550, 100, 50), corRoomTextures[2 + roomNum])) { if (Inventory.getAmountOfPiece(1) > 0) { refBlock.GetComponent <Block> ().addPiece(Resources.Load("CornerRoom") as GameObject, new Vector3(0, 180, 0)); for (int i = 0; i < possibilities.Length; i++) { possibilities [i] = false; } isPlacingPiece = false; } } GUI.Label(new Rect(x, 600, 100, 50), "Amount Left: " + Inventory.getAmountOfPiece(1)); x += 100; } if (possibilities [5]) { if (GUI.Button(new Rect(x, 550, 100, 50), corRoomTextures[3 + roomNum])) { if (Inventory.getAmountOfPiece(1) > 0) { refBlock.GetComponent <Block> ().addPiece(Resources.Load("CornerRoom") as GameObject, new Vector3(0, 270, 0)); for (int i = 0; i < possibilities.Length; i++) { possibilities [i] = false; } isPlacingPiece = false; } } GUI.Label(new Rect(x, 600, 100, 50), "Amount Left: " + Inventory.getAmountOfPiece(1)); x += 100; } if (possibilities [6]) { if (GUI.Button(new Rect(x, 550, 100, 50), threeRoomTextures[roomNum])) { if (Inventory.getAmountOfPiece(2) > 0) { refBlock.GetComponent <Block> ().addPiece(Resources.Load("ThreeDoorRoom") as GameObject, new Vector3(0, 0, 0)); for (int i = 0; i < possibilities.Length; i++) { possibilities [i] = false; } isPlacingPiece = false; } } GUI.Label(new Rect(x, 600, 100, 50), "Amount Left: " + Inventory.getAmountOfPiece(2)); x += 100; } if (possibilities [7]) { if (GUI.Button(new Rect(x, 550, 100, 50), threeRoomTextures[1 + roomNum])) { if (Inventory.getAmountOfPiece(2) > 0) { refBlock.GetComponent <Block> ().addPiece(Resources.Load("ThreeDoorRoom") as GameObject, new Vector3(0, 90, 0)); for (int i = 0; i < possibilities.Length; i++) { possibilities [i] = false; } isPlacingPiece = false; } } GUI.Label(new Rect(x, 600, 100, 50), "Amount Left: " + Inventory.getAmountOfPiece(2)); x += 100; } if (possibilities [8]) { if (GUI.Button(new Rect(x, 550, 100, 50), threeRoomTextures[2 + roomNum])) { if (Inventory.getAmountOfPiece(2) > 0) { refBlock.GetComponent <Block> ().addPiece(Resources.Load("ThreeDoorRoom") as GameObject, new Vector3(0, 180, 0)); for (int i = 0; i < possibilities.Length; i++) { possibilities [i] = false; } isPlacingPiece = false; } } GUI.Label(new Rect(x, 600, 100, 50), "Amount Left: " + Inventory.getAmountOfPiece(2)); x += 100; } if (possibilities [9]) { if (GUI.Button(new Rect(x, 550, 100, 50), threeRoomTextures[3 + roomNum])) { if (Inventory.getAmountOfPiece(2) > 0) { refBlock.GetComponent <Block> ().addPiece(Resources.Load("ThreeDoorRoom") as GameObject, new Vector3(0, 270, 0)); for (int i = 0; i < possibilities.Length; i++) { possibilities [i] = false; } isPlacingPiece = false; } } GUI.Label(new Rect(x, 600, 100, 50), "Amount Left: " + Inventory.getAmountOfPiece(2)); x += 100; } if (possibilities [10]) { if (GUI.Button(new Rect(x, 550, 100, 50), InstantiateBlocks.getTextures()[10])) { if (Inventory.getAmountOfPiece(3) > 0) { refBlock.GetComponent <Block> ().addPiece(Resources.Load("FourDoorRoom") as GameObject, new Vector3(0, 0, 0)); for (int i = 0; i < possibilities.Length; i++) { possibilities [i] = false; } isPlacingPiece = false; } } GUI.Label(new Rect(x, 600, 100, 50), "Amount Left: " + Inventory.getAmountOfPiece(3)); x += 100; } x = 0; } #endregion }
int pieceType; //What the piece type is. Each int stands for a different piece void Start() { //Get the current row and column and store it curColumn = InstantiateBlocks.getCurColumn(this.gameObject.transform.position); curRow = InstantiateBlocks.getCurRow(this.gameObject.transform.position); //Instantiate ends and set all to true ends = new bool[4]; setEnds(true, true, true, true); //Check whether or not the piece has been created in another game isUsed = PlayerPrefs.GetInt(curRow.ToString() + curColumn.ToString() + "isUsed") == 1; #region LoadingAlreadyCreatedBlocks if (isUsed) { pieceType = PlayerPrefs.GetInt(curRow.ToString() + curColumn.ToString() + "pieceType"); if (pieceType == 1) { this.loadPiece(Resources.Load("TwoDoorRoom") as GameObject, new Vector3(0, 0, 0)); } else if (pieceType == 2) { this.loadPiece(Resources.Load("TwoDoorRoom") as GameObject, new Vector3(0, 90, 0)); } else if (pieceType == 3) { this.loadPiece(Resources.Load("CornerRoom") as GameObject, new Vector3(0, 0, 0)); } else if (pieceType == 4) { this.loadPiece(Resources.Load("CornerRoom") as GameObject, new Vector3(0, 90, 0)); } else if (pieceType == 5) { this.loadPiece(Resources.Load("CornerRoom") as GameObject, new Vector3(0, 180, 0)); } else if (pieceType == 6) { this.loadPiece(Resources.Load("CornerRoom") as GameObject, new Vector3(0, 270, 0)); } else if (pieceType == 7) { this.loadPiece(Resources.Load("ThreeDoorRoom") as GameObject, new Vector3(0, 0, 0)); } else if (pieceType == 8) { this.loadPiece(Resources.Load("ThreeDoorRoom") as GameObject, new Vector3(0, 90, 0)); } else if (pieceType == 9) { this.loadPiece(Resources.Load("ThreeDoorRoom") as GameObject, new Vector3(0, 180, 0)); } else if (pieceType == 10) { this.loadPiece(Resources.Load("ThreeDoorRoom") as GameObject, new Vector3(0, 270, 0)); } else if (pieceType == 11) { this.loadPiece(Resources.Load("FourDoorRoom") as GameObject, new Vector3(0, 0, 0)); } #endregion } }