//Method to make the buying system work. public void BuyItem(BarrackItem item) { //Check if the player has the amount of gold needed to buy the Unit. if (gm.playerTurn == 1 && item.cost <= gm.player1Gold) { gm.player1Gold -= item.cost; player1Menu.SetActive(false); } else if (gm.playerTurn == 2 && item.cost <= gm.player2Gold) { gm.player2Gold -= item.cost; player2Menu.SetActive(false); } else { print("Not enough Gold!"); return; } gm.UpdateGoldText(); gm.purchasedItem = item; if (gm.selectedUnit != null) { gm.selectedUnit.selected = false; gm.selectedUnit = null; } GetCreatableTiles(); }
public void BuyItem(BarrackItem item) { if (gm.playerTurn == 1 && item.cost <= gm.player1Gold)//check to see if the player has enough gold { gm.player1Gold -= item.cost; player1Menu.SetActive(false); } else if (gm.playerTurn == 2 && item.cost <= gm.player2Gold) { gm.player2Gold -= item.cost; player2Menu.SetActive(false); } else //if player doe not have enough gold { print("Insufficient gold."); return; //exit the function } gm.UpdateGoldText(); //update the ui after a purchase gm.purchasedItem = item; if (gm.selectedUnit != null) //deselect any selected units to prepare to create a unit { gm.selectedUnit.selected = false; gm.selectedUnit = null; } GetCreatableTiles(); }
public void BuyUnit(BarrackItem item) { if (gm.playerTurn == 1 && item.cost <= gm.player1Gold) { gm.player1Gold -= item.cost; player1Menu.SetActive(false); } else if (gm.playerTurn == 2 && item.cost <= gm.player2Gold) { player2Menu.SetActive(false); gm.player2Gold -= item.cost; } else { print("NOT ENOUGH GOLD, SORRY!"); return; } gm.UpdateGoldText(); gm.purchasedItem = item; if (gm.selectedUnit != null) { gm.selectedUnit.selected = false; gm.selectedUnit = null; } // DeselectUnit(); GetCreatableTiles(); }
public void BuyItem(BarrackItem item) { if (gm.playerTurn == 1 && item.cost <= gm.player1Gold) { gm.player1Gold -= item.cost; player1Menu.SetActive(false); } else if (gm.playerTurn == 2 && item.cost <= gm.player2Gold) { gm.player2Gold -= item.cost; player2Menu.SetActive(false); } else { print("NOT ENOUGH GOLD!"); return; } gm.UpdateGoldText(); gm.purchasedItem = item; //stores the currently purchased unit if (gm.selectedUnit != null) { gm.selectedUnit.selected = false; gm.selectedUnit = null; } GetCreatableTiles(); }
private void OnMouseDown() { if (isWalkable && gm.selectedUnit != null) { gm.selectedUnit.Move(this.transform.position); } else if (isCreatable == true) { BarrackItem item = Instantiate(gm.purchasedItem, new Vector2(transform.position.x, transform.position.y), Quaternion.identity); //spawns the purchased item on the selected tile gm.ResetTiles(); Units unit = item.GetComponent <Units>(); if (unit != null) { unit.hasAttacked = true; unit.hasMoved = true; } } }
private void OnMouseDown() { if (isWalkable == true && gm.selectedUnit != null) { gm.selectedUnit.Move(this.transform); } else if (isCreatable) { BarrackItem item = Instantiate(gm.purchasedItem, new Vector2(Mathf.Round(transform.position.x), Mathf.Round(transform.position.y)), Quaternion.identity); gm.ResetTiles(); Units unit = item.GetComponent <Units>(); if (unit != null) { unit.hasMoved = true; unit.hasAttack = true; } } }
private void OnMouseDown() { if (isWalkable == true && gm.selectedUnit != null) //if the tile is walkable and a unit is selected { gm.selectedUnit.Move(this.transform.position); } else if (isCreatable == true) { BarrackItem item = Instantiate(gm.purchasedItem, new Vector2(transform.position.x, transform.position.y), Quaternion.identity); gm.ResetTiles(); //instantiate the chosen unit type and reset tiles Unit unit = item.GetComponent <Unit>(); if (unit != null) //if a unit was purchased, not a chest, make sure it is unable to move that same turn { unit.hasMoved = true; unit.hasAttacked = true; } } }
private void OnMouseDown() { if (isWalkable && gm.SelectedUnit != null) { gm.SelectedUnit.Move(this.transform.position); } else if (isCreatable) { Debug.Log("Create"); BarrackItem item = Instantiate(gm.purchasedItem, new Vector2(transform.position.x, transform.position.y), Quaternion.identity); gm.ResetTiles(); Unit unit = item.GetComponent <Unit>(); if (unit != null) { unit.hasAttacked = true; unit.hasMoved = true; } } }
public void BuyItem(BarrackItem item) { if (gm.playerTurn == PlayerTurn.BLUE && item.Cost <= gm.Player1Gold) { gm.Player1Gold -= item.Cost; Player1Menu.SetActive(false); } else if (gm.playerTurn == PlayerTurn.RED && item.Cost <= gm.Player2Gold) { gm.Player2Gold -= item.Cost; Player2Menu.SetActive(false); } else { return; } gm.UpdateGoldText(); gm.purchasedItem = item; gm.SetSelectedUnit(null); GetCreatableTiles(); }