// Update is called once per frame void Update() { if (initialize == false) { gameManager = GetComponent <GameManager>(); UIManager = GetComponent <UIController>(); animController = GetComponent <TroopAnimController>(); board = GameObject.FindGameObjectWithTag("Board").GetComponent <Board>(); initialize = true; } if (gameManager.phase == Phase.Movement) { //if troop not already selected if (Dragging == false && SelectedTroop == null) { if (Input.GetMouseButtonDown(0)) { difX = 0; difY = 0; SelectTroop(); } } //if troop already selected else if (Dragging == true) { //left mouse click if (Input.GetMouseButtonDown(0)) { switch (gameManager.state) { case (State.TroopPlacement): //in the troop placement state //if troop is in the range of the board if ((SelectedTroop.transform.position.x >= board.Minx && SelectedTroop.transform.position.z >= board.Miny) && (SelectedTroop.transform.position.x <= board.Maxx && SelectedTroop.transform.position.z <= board.Maxy)) { //if the troop is a pawn if (SelectedTroop.tag == "Pawn") { PlacePawn(); //call the place pawn function } //if troop is anything else else { gameManager.PlaceTroop(); //call the place troop function } } break; case (State.Gameplay): //in the gameplay state //if player has moved troops position if (difX != 0 || difY != 0) { //if troop is a pawn if (SelectedTroop.tag == "Pawn") { //Maybe i can shorten this... //if red team turn and not all the pawns have been placed if (gameManager.turn == Turn.Red && pawnMoveCount < gameManager.RedPawnCount) { SelectedTroop.GetComponent <Pawn>().moved = true; gameManager.PlaceTroop(); pawnMoveCount++; //increase pawn moved count } //if red team turn and all the pawns have been placed else if (gameManager.turn == Turn.Red && pawnMoveCount == gameManager.RedPawnCount) { gameManager.PlaceTroop(); for (int i = 0; i < gameManager.RedPawns.Count; i++) { gameManager.RedPawns[i].GetComponent <Pawn>().moved = false; } pawnMoveCount = 1; //reset count gameManager.ChangePhase(); } //if blue team turn and not all the pawns have been placed if (gameManager.turn == Turn.Blue && pawnMoveCount < gameManager.BluePawnCount) { SelectedTroop.GetComponent <Pawn>().moved = true; gameManager.PlaceTroop(); pawnMoveCount++; //increase pawn moved count } //if blue team turn and all the pawns have been placed else if (gameManager.turn == Turn.Blue && pawnMoveCount == gameManager.BluePawnCount) { gameManager.PlaceTroop(); for (int i = 0; i < gameManager.BluePawns.Count; i++) { gameManager.BluePawns[i].GetComponent <Pawn>().moved = false; } pawnMoveCount = 1; //reset count gameManager.ChangePhase(); } //...Maybe i can shorten this } //if troop is a mage else if (SelectedTroop.tag == "Mage" && dif > troopScript.moveDist) { //if tile is out of his movement range if (dif > troopScript.moveDist) { awaitingResponse = true; //wait for players response Dragging = false; //stop moving the mage whilst waiting } //if tile is in his movement range else { //palce troop as normal and change phase gameManager.PlaceTroop(); gameManager.ChangePhase(); } } //if troop is anything else else { //place troop and change phase gameManager.PlaceTroop(); gameManager.ChangePhase(); } } //if player hasn't moved troops position else if (difX == 0 && difY == 0) { //place troop but dont chance phase gameManager.PlaceTroop(); } break; default: break; } } if (Input.GetMouseButtonDown(1)) { SelectedTroop.transform.position = storedPos; Dragging = false; SelectedTroop = null; troopScript = null; Debug.Log("hi"); } if (SelectedTroop != null) { if (SelectedTroop.tag == "Mage") { SkinnedMeshRenderer renderer = SelectedTroop.GetComponentInChildren <SkinnedMeshRenderer>(); if (troopScript.team == Team.Red && mageFullOpac == true && renderer != redMageFullOpac) { notChanged = true; } else if (troopScript.team == Team.Red && mageFullOpac == false && renderer != redMageHalfOpac) { notChanged = true; } else if (troopScript.team == Team.Blue && mageFullOpac == true && renderer != blueMageFullOpac) { notChanged = true; } else if (troopScript.team == Team.Blue && mageFullOpac == false && renderer != blueMageHalfOpac) { notChanged = true; } else { notChanged = false; } } } } if (awaitingResponse == true) { //rewrite debug log to ask question in UI //Debug.Log("About to use mages ability, do you want to continue? Y/N"); UIManager.MageQuestion(); if (UIManager.YesNo == yesno.yes) //if player presses Y key activate mage ability { mageFullOpac = true; ChangeMageOpac(); //Move mage and go to checks //TroopHit.transform.position = moveTo; gameManager.PlaceTroop(); gameManager.ChangePhase(); gameManager.ChangePhase(); awaitingResponse = false; //stop calling this UIManager.HideQuestion(); UIManager.YesNo = yesno.notSelected; } else if (UIManager.YesNo == yesno.no) //if player presses N key { //nothing happens, player chooses new tile for mage Dragging = true; awaitingResponse = false; //stop calling this UIManager.HideQuestion(); UIManager.YesNo = yesno.notSelected; } } } else if (gameManager.phase == Phase.Checks) { if (Dragging == true) { //this switch method will allow me to easily add new abilities and checks switch (gameManager.CheckCount) { case (0): //if priest ability if (Input.GetMouseButtonDown(0)) { //Debug.Log("Test1"); if (SelectedTroop.tag == "Pawn") { //set it so it spawns multiple pawns until there are 3 on the board if (gameManager.turn == Turn.Red && gameManager.RedPawnCount < 2) { GameObject RedPawn = Instantiate(gameManager.RedPawnPrefab, new Vector3(moveTo.x, 0.1f, moveTo.z), new Quaternion(0, 0, 0, 0)); //instantiate new gameobject, rotate to face red team if (pawnSpawnCount == 0) { pawnOne = RedPawn; } else if (pawnSpawnCount == 1) { pawnTwo = RedPawn; } //else if (pawnSpawnCount == 2) { pawnThree = RedPawn; } pawnSpawnCount++; RedPawn.transform.SetParent(GameObject.FindGameObjectWithTag("RedTeam").transform); //set its parent object to its team RedPawn.name = "RedPawn"; //rename pawn RedPawn.GetComponent <TroopScript>().troopState = TroopState.Alive; RedPawn.GetComponent <TroopScript>().Anim = RedPawn.GetComponent <Animator>(); StartCoroutine(RedPawn.GetComponent <TroopScript>().PlayReviveAnim()); } else if (gameManager.turn == Turn.Red && gameManager.RedPawnCount <= 2) { gameManager.priestRedRevive = true; SelectedTroop.GetComponent <TroopScript>().ResetHealth(); SelectedTroop.GetComponent <TroopScript>().troopState = TroopState.Alive; StartCoroutine(animController.ReviveAnim(gameManager, SelectedTroop)); gameManager.PlaceTroop(); gameManager.PauseChecks = false; gameManager.CheckCount++; spawningTroop = false; StartCoroutine(gameManager.PerformChecks()); } else if (gameManager.turn == Turn.Blue && gameManager.BluePawnCount < 2) { GameObject BluePawn = Instantiate(gameManager.BluePawnPrefab, new Vector3(moveTo.x, 0.1f, moveTo.z), new Quaternion(0, 1, 0, 0)); //instantiate new gameobject, rotate to face red team if (pawnSpawnCount == 0) { pawnOne = BluePawn; } else if (pawnSpawnCount == 1) { pawnTwo = BluePawn; } //else if (pawnSpawnCount == 2) { pawnThree = BluePawn; } pawnSpawnCount++; //Debug.Log("Plus one in spawn count"); BluePawn.transform.SetParent(GameObject.FindGameObjectWithTag("BlueTeam").transform); //set its parent object to its team BluePawn.name = "BluePawn"; //rename pawn BluePawn.GetComponent <TroopScript>().troopState = TroopState.Alive; BluePawn.GetComponent <TroopScript>().Anim = BluePawn.GetComponent <Animator>(); StartCoroutine(BluePawn.GetComponent <TroopScript>().PlayReviveAnim()); } else if (gameManager.turn == Turn.Blue && gameManager.BluePawnCount <= 2) { Debug.Log("Test2"); gameManager.priestBlueRevive = true; SelectedTroop.GetComponent <TroopScript>().ResetHealth(); SelectedTroop.GetComponent <TroopScript>().troopState = TroopState.Alive; StartCoroutine(animController.ReviveAnim(gameManager, SelectedTroop)); gameManager.PlaceTroop(); gameManager.PauseChecks = false; gameManager.CheckCount++; spawningTroop = false; StartCoroutine(gameManager.PerformChecks()); } } else { Debug.Log("Test3"); SelectedTroop.GetComponent <TroopScript>().ResetHealth(); SelectedTroop.GetComponent <TroopScript>().troopState = TroopState.Alive; StartCoroutine(animController.ReviveAnim(gameManager, SelectedTroop)); gameManager.PlaceTroop(); spawningTroop = false; if (gameManager.turn == Turn.Red) { gameManager.priestRedRevive = true; } else if (gameManager.turn == Turn.Blue) { gameManager.priestBlueRevive = true; } } } if (Input.GetMouseButtonDown(1)) { Debug.Log("hi"); if (SelectedTroop.tag == "Pawn" && pawnSpawnCount >= 1) { //if (pawnSpawnCount == 1) { Destroy (pawnOne); } //else if (pawnSpawnCount == 2) { Destroy(pawnOne); Destroy(pawnTwo); } if (pawnOne != null) { Destroy(pawnOne); } //else if (pawnSpawnCount == 3) { Destroy(pawnOne); Destroy(pawnTwo); Destroy(pawnThree); } } Dragging = false; var MoveTroop = new Vector3(SelectedTroop.transform.position.x, -5, SelectedTroop.transform.position.x); SelectedTroop.transform.position = MoveTroop; spawningTroop = false; SelectedTroop = null; troopScript = null; UIManager.RevealDeadTroops(); } break; default: break; } } if (kingAbility == true) { switch (gameManager.turn) { case (Turn.Red): if (spawnedRedPawn.transform.position == moveTo) { if (Input.GetMouseButtonDown(0)) { PlacePawn(); } } break; case (Turn.Blue): if (spawnedBluePawn.transform.position == moveTo) { if (Input.GetMouseButtonDown(0)) { PlacePawn(); } } break; default: break; } } } }