}//end SendCurrent public void RemoveCurrent() { GameObject tm = GameObject.FindGameObjectWithTag("tile_manager"); Tile_Manager_Script tm_script = tm.GetComponent <Tile_Manager_Script>(); Node_Attributes att = GetComponent <Node_Attributes>(); int x = (int)att.x_coord; int y = (int)att.y_coord; GameObject[] nearby = new GameObject[4]; //put this into a separate method nearby[0] = tm_script.GetTile(x, y + 1); //top right nearby[1] = tm_script.GetTile(x + 1, y); //top left nearby[2] = tm_script.GetTile(x - 1, y); //bottom right nearby[3] = tm_script.GetTile(x, y - 1); //bottom left foreach (GameObject tile in nearby) { if (tile != null && tile.GetComponent <Node_Attributes>()._type == nodeType._wire) { tile.GetComponent <Wire_Script>().current = false; tile.GetComponent <Wire_Script>().RemoveCurrent(); } } } //end RemoveCurrent
//function to name and set the coordinates of each tile void InitializeTile(GameObject tile, int x, int y) { //name the tile based on its coordinate string tile_name = "(" + x + "," + y + ")"; tile.name = tile_name; //fill in the tile's coordinates Node_Attributes att = tile.GetComponent <Node_Attributes>(); att.x_coord = x; att.y_coord = y; }
public void ArrayContents() { int x = tile_array.GetLength(0); int y = tile_array.GetLength(1); for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { GameObject tile = tile_array[i, j]; Node_Attributes att = tile.GetComponent <Node_Attributes>(); Debug.Log(att.x_coord + ", " + att.y_coord); } } Debug.Log(x + ", " + y); }
public void SendCurrent() { GameObject tm = GameObject.FindGameObjectWithTag("tile_manager"); Tile_Manager_Script tm_script = tm.GetComponent <Tile_Manager_Script>(); Node_Attributes att = GetComponent <Node_Attributes>(); //TE: These check the parameters of the tile and change it's sprite accordingly. NOTE: this uses the individual sprites in the Resources folder NOT the ones in Sprites, hence why they are named without the "work" as to make an easy visible distinction. int x = (int)att.x_coord; int y = (int)att.y_coord; GameObject[] nearby = new GameObject[4]; //put this into a separate method nearby[0] = tm_script.GetTile(x, y + 1); //top right nearby[1] = tm_script.GetTile(x + 1, y); //top left nearby[2] = tm_script.GetTile(x - 1, y); //bottom right nearby[3] = tm_script.GetTile(x, y - 1); //bottom left if (nearby[0] != null && nearby[0].GetComponent <Node_Attributes>()._type == nodeType._wire) { if (this.connectTopR == true && nearby[0].GetComponent <Wire_Script>().connectBotL == true && nearby[0].GetComponent <Wire_Script>().current == false) { nearby[0].GetComponent <Wire_Script>().current = true; nearby[0].GetComponent <Wire_Script>().SendCurrent(); } } if (nearby[1] != null && nearby[1].GetComponent <Node_Attributes>()._type == nodeType._wire) { if (this.connectTopL == true && nearby[1].GetComponent <Wire_Script>().connectBotR == true && nearby[1].GetComponent <Wire_Script>().current == false) { nearby[1].GetComponent <Wire_Script>().current = true; nearby[1].GetComponent <Wire_Script>().SendCurrent(); } } if (nearby[2] != null && nearby[2].GetComponent <Node_Attributes>()._type == nodeType._wire) { if (this.connectBotR == true && nearby[2].GetComponent <Wire_Script>().connectTopL == true && nearby[2].GetComponent <Wire_Script>().current == false) { nearby[2].GetComponent <Wire_Script>().current = true; nearby[2].GetComponent <Wire_Script>().SendCurrent(); } } if (nearby[3] != null && nearby[3].GetComponent <Node_Attributes>()._type == nodeType._wire) { if (this.connectBotL == true && nearby[3].GetComponent <Wire_Script>().connectTopR == true && nearby[3].GetComponent <Wire_Script>().current == false) { nearby[3].GetComponent <Wire_Script>().current = true; nearby[3].GetComponent <Wire_Script>().SendCurrent(); } } //goal checker if (nearby[0] != null && nearby[0].GetComponent <Node_Attributes>()._type == nodeType._goal) { if (this.connectTopR == true) { nearby[0].GetComponent <Goal_Script>().current = true; nearby[0].GetComponent <Goal_Script>().victory(); } } if (nearby[1] != null && nearby[1].GetComponent <Node_Attributes>()._type == nodeType._goal) { if (this.connectTopL == true) { nearby[1].GetComponent <Goal_Script>().current = true; nearby[1].GetComponent <Goal_Script>().victory(); } } if (nearby[2] != null && nearby[2].GetComponent <Node_Attributes>()._type == nodeType._goal) { if (this.connectBotR == true) { nearby[2].GetComponent <Goal_Script>().current = true; nearby[2].GetComponent <Goal_Script>().victory(); } } if (nearby[3] != null && nearby[3].GetComponent <Node_Attributes>()._type == nodeType._goal) { if (this.connectBotL == true) { nearby[3].GetComponent <Goal_Script>().current = true; nearby[3].GetComponent <Goal_Script>().victory(); } } }//end SendCurrent