void OnMouseDown() { //Grab Selected Unit From Main Script mainUnit_Selected = main_Script.mainUnit_Selected; if (mainUnit_Selected != null) { main_Script.MoveUnit(this); } }
//Function to Generate all Units public void GenerateUnit(int x, int y, bool color) { //Create the GameObject GameObject unit_GameObject; //Create White or Black Units if (color == true) { //Set the GameObject from the Prefab unit_GameObject = Instantiate(whiteUnit_Prefab) as GameObject; //Sets the name of GameObject. unit_GameObject.name = "White Unit X: " + x + " / Y: " + y; } else { //Set the GameObject from the Prefab unit_GameObject = Instantiate(blackUnit_Prefab) as GameObject; //Sets the name of GameObject. unit_GameObject.name = "Black Unit X: " + x + " / Y: " + y; } //Add Script to GameObject unit_GameObject.AddComponent <MyOwnUnit>(); //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 unit_XY = new Vector3(smoolX, 0.025f, smoolY); unit_GameObject.transform.position = unit_XY; //Grab Script from the GameObject and set entity dependant Script variables MyOwnUnit unit_Script = unit_GameObject.GetComponent <MyOwnUnit>(); unit_Script.x = x; unit_Script.y = y; unit_Script.IsWhite = color; //Add GameObject to Array with coords as refference ID unitGO_Array[x, y] = unit_GameObject; }
void OnMouseDown() { if (IsPlayersTurn() == true) { //Grab Selected Unit From Main Script mainUnit_Selected = main_Script.mainUnit_Selected; //Play SFX on GameObject unit_AudioSource.PlayOneShot(emptyTile_SFX); //if Main Script does not have a Unit already if (mainUnit_Selected == null) { //if the unit is selected already remove glow Mat if not apply it if (unit_Selected == false) { SelectUnit(); } else { UnselectUnit(); } } else //if Main Script has a Unit already { if (mainUnit_Selected == this) { //Unselect its own Unit UnselectUnit(); } else { //Remove the prevouis other Unit Selection mainUnit_Selected.UnselectUnit(); //Set this Unit SelectUnit(); } } } }
//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; } } } }