public void chooseActionMode(string actionMode)
    {
        if (strLastSelectSoldierName != "")
        {
            destroyAttackArrow();
        }

        actionModeName = actionMode;
        if (selectedSoldier != null)
        {
            switch (actionModeName)
            {
            case "Attack":
                if (selectedSoldier.GetComponent <Unit>().m_pSoldier.getCurrentMoveStep() > 0)
                {
                    actionModeName = "Attack";
                    GameObject newAttackArrow = Instantiate(attackArrow, selectedSoldier.transform.position, Quaternion.identity);
                    newAttackArrow.name      = selectedSoldier.name + "_attackArrow";
                    strLastSelectSoldierName = newAttackArrow.name;
                    m_pUnit.setState(1);
                }
                break;

            case "Defense":
                actionModeName = "Defense";
                int blockAttack = m_pUnit.getCurrentMoveStep();
                m_pUnit.setDefense(blockAttack);
                m_pUnit.setCurrentMoveStep(0);
                m_pUnit.setState(2);
                GameObject floatingTextObj = Instantiate(floatingText, selectedSoldier.transform.position, Quaternion.identity);
                floatingTextObj.GetComponent <TextMesh>().text  = "Block " + blockAttack.ToString() + " hit!";
                floatingTextObj.GetComponent <TextMesh>().color = Color.white;
                SoundEffectManager.Instance.playAudio(12);
                break;

            case "LevelUP":
                actionModeName = "Defense";
                m_pUnit.setState(3);
                break;

            case "Sell":
                int value = m_pUnit.getMoneyBySellingEntity();
                if (GameManager.Instance.getTurn() == 0)
                {
                    m_player1.setMoney(m_player1.getMoney() + m_pUnit.getMoneyBySellingEntity());
                }
                else
                {
                    m_player2.setMoney(m_player2.getMoney() + m_pUnit.getMoneyBySellingEntity());
                }
                Destroy(selectedSoldier);
                m_pUnit.setState(4);
                Vector2    pos     = new Vector2(cameraMain.transform.position.x + 2, cameraMain.transform.position.y - 1);
                GameObject popText = Instantiate(floatingText, pos, Quaternion.identity);
                popText.GetComponent <TextMesh>().text = "money+" + value.ToString();
                SoundEffectManager.Instance.playAudio(0);
                break;
            }
        }
    }
Beispiel #2
0
    //当士兵到达目的地之后,绿色消失
    void whenUnitFirstArriveDestination()
    {
        if (thisUnitHasBeenClicked == false)
        {
            for (int i = 0; i < greenTiles.Count; i++)
            {
                greenTiles[i].GetComponent <SpriteRenderer>().color = Color.white;
            }
            greenTiles.Clear();
        }
        //thisUnitHasBeenClicked = false;
        GameObject pTile      = GameObject.Find("Terrain_" + destinationXIndex.ToString() + "_" + destinationYIndex.ToString());
        int        spriteType = pTile.GetComponent <TileScript>().spriteType;

        //碰到金矿图,金钱+15
        if (spriteType == 4)
        {
            if (GameManager.Instance.getTurn() == 0)
            {
                m_player1.modifyMoney(15);
            }
            else if (GameManager.Instance.getTurn() == 1)
            {
                m_player2.modifyMoney(15);
            }
            pTile.GetComponent <SpriteRenderer>().sprite = GameManager.Instance.terrainSprites[3];
            pTile.GetComponent <TileScript>().spriteType = 3;
            GameObject popText = Instantiate(floatingText, transform.position, Quaternion.identity);
            popText.GetComponent <TextMesh>().text  = "Money+$15";
            popText.GetComponent <TextMesh>().color = Color.yellow;
            SoundEffectManager.Instance.playAudio(0);
        }
        //碰到奶牛图,血量+10
        if (spriteType == 5)
        {
            m_pSoldier.modifyHP(10);
            pTile.GetComponent <SpriteRenderer>().sprite = GameManager.Instance.terrainSprites[0];
            pTile.GetComponent <TileScript>().spriteType = 0;
            GameObject popText = Instantiate(floatingText, transform.position, Quaternion.identity);
            popText.GetComponent <TextMesh>().text  = "HP+10";
            popText.GetComponent <TextMesh>().color = Color.green;
            SoundEffectManager.Instance.playAudio(1);
        }
        m_pSoldier.setCurrentMoveStep(m_pSoldier.getCurrentMoveStep() - 1);

        //到达终点
        if (GameManager.Instance.getTurn() == 0)
        {
            if (destinationXIndex == 7 && destinationYIndex == 11)
            {
                UIManager.Instance.endingScenePanel.SetActive(true);
                UIManager.Instance.endingScenePanel.GetComponent <Image>().sprite = UIManager.Instance.orangeWin;
            }
        }
        else if (GameManager.Instance.getTurn() == 1)
        {
            if (destinationXIndex == 7 && destinationYIndex == 0)
            {
                UIManager.Instance.endingScenePanel.SetActive(true);
                UIManager.Instance.endingScenePanel.GetComponent <Image>().sprite = UIManager.Instance.purpleWin;
            }
        }
    }