Exemplo n.º 1
0
    /////////////////////////////////////////////////////////////////////////////

    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();
    }
Exemplo n.º 2
0
    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();
                }
            }
        }
    }