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; } } }
//显示士兵信息 public void showUnitInformation(bool bShowInformation) { if (selectedUnit == null) { return; } if (bShowInformation == true) { SoldierType.Soldiers thisUnit = selectedUnit.m_pSoldier; int maxHP = thisUnit.getMaxHP(); UIManager.Instance.maxHP.GetComponent <Text>().text = maxHP.ToString(); int attack = thisUnit.getAttack(); UIManager.Instance.attackValue.GetComponent <Text>().text = attack.ToString(); int maxStep = thisUnit.getMaxMoveStep(); UIManager.Instance.maxMoveStep.GetComponent <Text>().text = maxStep.ToString(); UIManager.Instance.soldierTypeName.GetComponent <Text>().text = thisUnit.returnTypeName(); int currentHP = thisUnit.getCurrentHP(); UIManager.Instance.currentHP.GetComponent <Text>().text = currentHP.ToString(); int currentMoveStep = thisUnit.getCurrentMoveStep(); UIManager.Instance.currentMoveStep.GetComponent <Text>().text = currentMoveStep.ToString(); UIManager.Instance.soldierTypeImage.sprite = UIManager.Instance.unitSprites[thisUnit.returnSpriteIndex()]; } else { UIManager.Instance.maxHP.GetComponent <Text>().text = null; UIManager.Instance.attackValue.GetComponent <Text>().text = null; UIManager.Instance.maxMoveStep.GetComponent <Text>().text = null; UIManager.Instance.soldierTypeName.GetComponent <Text>().text = null; UIManager.Instance.soldierTypeImage.sprite = UIManager.Instance.noSprite; UIManager.Instance.currentMoveStep.GetComponent <Text>().text = null; UIManager.Instance.currentHP.GetComponent <Text>().text = null; } }
void mouseClickHex(GameObject pTile) { if (Input.GetMouseButton(0)) { //pTile.GetComponent<SpriteRenderer>().color = Color.red; if (selectedUnit == null) { return; } SoldierType.Soldiers thisSelectedUnitType = selectedUnit.m_pSoldier; if (clickUnit == false && !CheckIfHasSoldierInGrid() && soldierActionScript.actionModeName != "Attack" && thisSelectedUnitType.getCurrentMoveStep() > 0) { if (selectedUnit.greenTiles.Contains(pTile)) { if (selectedUnitObject == null) { return; } selectedUnit.destination = pTile.transform.position; int x = GameManager.Instance.getTileIndexXDic(pTile.name); GameManager.Instance.setUnitPosXIndex(selectedUnitObject.name, x); int y = GameManager.Instance.getTileIndexYDic(pTile.name); GameManager.Instance.setUnitPosYIndex(selectedUnitObject.name, y); selectedUnit.destinationXIndex = x; selectedUnit.destinationYIndex = y; selectedUnit.indexX = x; selectedUnit.indexY = y; Debug.Log("Destination: " + "xIndex: " + x + " yIndex: " + y); if (selectedUnit.entityType == 1 || selectedUnit.entityType == 2 || selectedUnit.entityType == 4 || selectedUnit.entityType == 6 || selectedUnit.entityType == 8) { SoundEffectManager.Instance.playAudio(4); } else if (selectedUnit.entityType == 3) { SoundEffectManager.Instance.playAudio(11); } else if (selectedUnit.entityType == 7 || selectedUnit.entityType == 5) { SoundEffectManager.Instance.playAudio(7); } //thisSelectedUnitType.setCurrentMoveStep(1); } } } }
//当士兵到达目的地之后,绿色消失 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; } } }