//当士兵到达目的地之后,绿色消失 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; } } }
//改变回合 public void setTurn() { if (mouseControllerScript.selectedUnitObject != null) { mouseControllerScript.selectedUnitObject = null; } UIManager.Instance.soldierActionPanel.SetActive(false); mouseControllerScript.showUnitInformation(false); 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; //当现在的回合是橙色方,变成紫色方 if (turn == 0) { turn = 1; myMainCamera.transform.position = new Vector3(0, 12, -10); //玩家金钱自然增长2 myPlayer2.modifyMoney(2); ///* if (soldier2Dic.Count > 0) { for (int i = 0; i < soldier2Dic.Count; i++) { if (soldier2Dic.ElementAt(i).Value == null) { return; } soldier2Dic.ElementAt(i).Value.GetComponent <Unit>().m_pSoldier.resetState(); soldier2Dic.ElementAt(i).Value.GetComponent <SpriteRenderer>().color = new Color(253, 0, 255); //soldier2Dic.ElementAt(i).Value.GetComponent<SpriteRenderer>().color = Color.white; } } //*/ if (soldier1Dic.Count > 0) { for (int i = 0; i < soldier1Dic.Count; i++) { if (soldier1Dic.ElementAt(i).Value == null) { return; } soldier1Dic.ElementAt(i).Value.GetComponent <SpriteRenderer>().color = new Color(255, 185, 0); } } } else { turn = 0; //玩家金钱自然增长2 myPlayer1.modifyMoney(2); myMainCamera.transform.position = new Vector3(0, 0, -10); ///* if (soldier1Dic.Count > 0) { for (int i = 0; i < soldier1Dic.Count; i++) { if (soldier1Dic.ElementAt(i).Value == null) { return; } soldier1Dic.ElementAt(i).Value.GetComponent <Unit>().m_pSoldier.resetState(); } } // */ if (soldier2Dic.Count > 0) { for (int i = 0; i < soldier2Dic.Count; i++) { if (soldier2Dic.ElementAt(i).Value == null) { return; } soldier2Dic.ElementAt(i).Value.GetComponent <SpriteRenderer>().color = new Color(253, 0, 255); //soldier2Dic.ElementAt(i).Value.GetComponent<SpriteRenderer>().color = Color.white; } } } restoreAllHexColor(); mouseControllerScript.ReserStatuOnChangeTurn(); if (soldierAction.GetComponent <SoldierActions>().preEnemyObject != null) { soldierAction.GetComponent <SoldierActions>().preEnemyObject = null; } }
public void instantiateUnit(int nType) { if (GameManager.Instance.getTurn() == 0) { soldierUnit.GetComponent <Unit>().setEntity(nType, 0); if (soldierUnit.GetComponent <Unit>().m_pSoldier.getMoneyToBuyEntity() > m_player1.getMoney()) { return; } else { SoundEffectManager.Instance.playAudio(3); int nAlign = GameManager.Instance.getTurn(); int posXIndex = (GameManager.Instance.width - 1) / 2; int posYIndex = 0; if (nAlign == 0) { posYIndex = 0; } else { posYIndex = GameManager.Instance.height - 1; } Vector2 pos = GameManager.Instance.getTerrainPos(posXIndex, posYIndex); //GameObject pSoldierUnit = soldierUnit; GameObject pSoldierUnit = Instantiate(soldierUnit, pos, Quaternion.identity); //Instantiate(soldierUnit, pos, Quaternion.identity); pSoldierUnit.name = "nType_" + nType + "nAlign_" + nAlign + "Index_" + totalUnitNum; pSoldierUnit.GetComponent <Unit>().setEntity(nType, nAlign); pSoldierUnit.GetComponent <Unit>().indexX = posXIndex; pSoldierUnit.GetComponent <Unit>().indexY = posYIndex; if (nAlign == 1) { pSoldierUnit.GetComponent <SpriteRenderer>().color = new Color(253, 0, 255); } else { pSoldierUnit.GetComponent <SpriteRenderer>().color = new Color(255, 185, 0); } if (GameManager.Instance.getTurn() == 0) { GameManager.Instance.setSoldierObjectDic1(pSoldierUnit.name, pSoldierUnit); } else { GameManager.Instance.setSoldierObjectDic2(pSoldierUnit.name, pSoldierUnit); } GameManager.Instance.setUnitPosXIndex(pSoldierUnit.name, posXIndex); GameManager.Instance.setUnitPosYIndex(pSoldierUnit.name, posYIndex); GameManager.Instance.setSoldierAlign(pSoldierUnit.name, nAlign); GameManager.Instance.setSoldierType(pSoldierUnit.name, nType); //Debug.Log("pSoldierUnit.name: "+ pSoldierUnit.name+ " pSoldierUnit posXIndex: "+ GameManager.Instance.getUnitPosXIndex(pSoldierUnit.name) + " pSoldierUnit posYIndex: " + GameManager.Instance.getUnitPosYIndex(pSoldierUnit.name)); totalUnitNum++; m_player1.modifyMoney(-pSoldierUnit.GetComponent <Unit>().m_pSoldier.getMoneyToBuyEntity()); } } else if (GameManager.Instance.getTurn() == 1) { soldierUnit.GetComponent <Unit>().setEntity(nType, 1); if (soldierUnit.GetComponent <Unit>().m_pSoldier.getMoneyToBuyEntity() > m_player2.getMoney()) { return; } else { SoundEffectManager.Instance.playAudio(3); int nAlign = GameManager.Instance.getTurn(); int posXIndex = (GameManager.Instance.width - 1) / 2; int posYIndex = 0; if (nAlign == 0) { posYIndex = 0; } else { posYIndex = GameManager.Instance.height - 1; } Vector2 pos = GameManager.Instance.getTerrainPos(posXIndex, posYIndex); //GameObject pSoldierUnit = soldierUnit; GameObject pSoldierUnit = Instantiate(soldierUnit, pos, Quaternion.identity); //Instantiate(soldierUnit, pos, Quaternion.identity); pSoldierUnit.name = "nType_" + nType + "nAlign_" + nAlign + "Index_" + totalUnitNum; pSoldierUnit.GetComponent <Unit>().setEntity(nType, nAlign); pSoldierUnit.GetComponent <Unit>().indexX = posXIndex; pSoldierUnit.GetComponent <Unit>().indexY = posYIndex; if (nAlign == 1) { pSoldierUnit.GetComponent <SpriteRenderer>().color = new Color(253, 0, 255); } else { pSoldierUnit.GetComponent <SpriteRenderer>().color = new Color(255, 185, 0); } if (GameManager.Instance.getTurn() == 0) { GameManager.Instance.setSoldierObjectDic1(pSoldierUnit.name, pSoldierUnit); } else { GameManager.Instance.setSoldierObjectDic2(pSoldierUnit.name, pSoldierUnit); } GameManager.Instance.setUnitPosXIndex(pSoldierUnit.name, posXIndex); GameManager.Instance.setUnitPosYIndex(pSoldierUnit.name, posYIndex); GameManager.Instance.setSoldierAlign(pSoldierUnit.name, nAlign); GameManager.Instance.setSoldierType(pSoldierUnit.name, nType); //Debug.Log("pSoldierUnit.name: "+ pSoldierUnit.name+ " pSoldierUnit posXIndex: "+ GameManager.Instance.getUnitPosXIndex(pSoldierUnit.name) + " pSoldierUnit posYIndex: " + GameManager.Instance.getUnitPosYIndex(pSoldierUnit.name)); totalUnitNum++; m_player2.modifyMoney(-pSoldierUnit.GetComponent <Unit>().m_pSoldier.getMoneyToBuyEntity()); } } }
public void setPlayer2(int nAlign) { m_Player2 = new PlayerAlign.Players(nAlign); m_Player2.modifyMoney(-2); GameManager.Instance.myPlayer2 = m_Player2; }