//Function to Generate all Tiles public void GenerateTile(int x, int y) { //Create the GameObject from the Prefab GameObject tile_GameObject = Instantiate(tile_Prefab) as GameObject; //Sets the Script of GameObject. tile_GameObject.AddComponent <MyOwnTile>(); //Sets the name of GameObject. tile_GameObject.name = "Tile X: " + x + " / Y: " + y; //Manipulate the X and Y coords to match the board size and position. float smoolX = x * 0.1f; float smoolY = y * 0.1f; //Set Vector3 value for position then transform the GameObject with the variable Vector3 tile_XY = new Vector3(smoolX, 0.0f, smoolY); tile_GameObject.transform.position = tile_XY; //Grab Script from the GameObject and set entity dependant Script variables MyOwnTile tile_Script = tile_GameObject.GetComponent <MyOwnTile>(); tile_Script.x = x; tile_Script.y = y; //Add GameObject to Array with coords as refference ID tileGO_Array[x, y] = tile_GameObject; }
public void CheckCollisionEnemy(MyOwnTile end_Tile) { //Get Unit Color for UI bool IsWhite = end_Tile.tiled_Unit.IsWhite; //Destroy the old Unit end_Tile.tiled_Unit.DestoryMe(); //Set UI for the Destruction UIUpdate_Destroy(IsWhite); }
///////////////////////////////////////////////////////////////////////////// public void MoveUnit(MyOwnTile end_Tile) { //Declare the Starting tile Class OBJ MyOwnTile start_Tile; //If the Unit is of the same Color Retun from function if (end_Tile.tiled_Unit != null) { if (end_Tile.tiled_Unit.IsWhite == mainUnit_Selected.IsWhite) { //Play the Corresponding SFX main_AudioSourceSFX.PlayOneShot(SameUnit_SFX); return; } } //Create new V3 with XY given by selected Tile then Chnages Unit position Vector3 newPosition_V3 = new Vector3((end_Tile.x * 0.1f), 0.025f, (end_Tile.y * 0.1f)); mainUnitSelected_GO.transform.position = newPosition_V3; //A Unit is already in this position! if (end_Tile.tiled_Unit != null) { //Play the Corresponding SFX main_AudioSourceSFX.PlayOneShot(CaptureUnit_SFX); CheckCollisionEnemy(end_Tile); } else { //Play the Corresponding SFX main_AudioSourceSFX.PlayOneShot(emptyTile_SFX); } //Get the Starting Tile and Remove the Unit refference start_Tile = mainUnit_Selected.Unit_tiled; start_Tile.tiled_Unit = null; //Set new Unit Coords mainUnit_Selected.x = end_Tile.x; mainUnit_Selected.y = end_Tile.y; //New Tile is Set to the Moved Unit + the vise versa end_Tile.tiled_Unit = mainUnit_Selected; mainUnit_Selected.Unit_tiled = end_Tile; //UnSelect after moving mainUnit_Selected.UnselectUnit(); //Update Turn counter and then The UI turnCounter++; UIUpdate_Turn(); }
public void SelectUnit() { unit_Selected = true; main_Script.mainUnit_Selected = this; main_Script.mainUnitSelected_GO = gameObject; //calc range int XXX = main_Script.mainUnit_Selected.x; int YYY = main_Script.mainUnit_Selected.y; if ((0 >= XXX + 1) && (main_Script.tileGO_Array.GetLength(0) >= XXX + 1)) { GameObject one = main_Script.tileGO_Array[XXX + 1, YYY]; MyOwnTile oneone = one.GetComponent <MyOwnTile>(); oneone.Highlight(); } if ((0 >= XXX - 1) && (main_Script.tileGO_Array.GetLength(0) >= XXX - 1)) { GameObject two = main_Script.tileGO_Array[XXX - 1, YYY]; MyOwnTile twotwo = two.GetComponent <MyOwnTile>(); twotwo.Highlight(); } if ((0 >= YYY + 1) && (main_Script.tileGO_Array.GetLength(1) >= YYY + 1)) { GameObject three = main_Script.tileGO_Array[XXX, YYY + 1]; MyOwnTile threethree = three.GetComponent <MyOwnTile>(); threethree.Highlight(); } if ((0 >= YYY - 1) && (main_Script.tileGO_Array.GetLength(1) >= YYY - 1)) { GameObject four = main_Script.tileGO_Array[XXX, YYY - 1]; MyOwnTile fourfour = four.GetComponent <MyOwnTile>(); fourfour.Highlight(); } //display range GetComponent <Renderer>().material = greyLight_Mat; }
//Link Units to Tiles public void Link_TileUnit() { for (int y = 0; y < 8; y++) { for (int x = 0; x < 8; x++) { //If a unit is in the array if (unitGO_Array[x, y] != null) { //Refference loop specific GameObjects GameObject tile_GO = tileGO_Array[x, y]; GameObject unit_GO = unitGO_Array[x, y]; //Get GameObject Componants MyOwnTile linkingTile_Script = tile_GO.GetComponent <MyOwnTile>(); MyOwnUnit linkingUnit_Script = unit_GO.GetComponent <MyOwnUnit>(); //Link the Classes to each other linkingTile_Script.tiled_Unit = linkingUnit_Script; linkingUnit_Script.Unit_tiled = linkingTile_Script; } } } }