Skip to content

Commit

Permalink
currency deduction on buy
Browse files Browse the repository at this point in the history
  • Loading branch information
minhd-vu committed Dec 10, 2021
1 parent ce1ba2e commit 8a271ae
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 9 additions & 0 deletions Assets/Scripts/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ public void Damage(int damage)
}
}

public bool Buy(int cost)
{
if (Currency < cost)
return false;

Currency -= cost;
return true;
}

public void Reward(int currency)
{
Currency += currency;
Expand Down
5 changes: 4 additions & 1 deletion Assets/Scripts/Tile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ void OnMouseDown()
return;

var building = BuildManager.instance.GetBuilding();
weapon = Instantiate(building, transform.position + building.transform.position, transform.rotation);
var cost = building.GetComponent<Weapon>().cost;

if (Player.instance.Buy(cost))
weapon = Instantiate(building, transform.position + building.transform.position, transform.rotation);
}
void OnMouseEnter()
{
Expand Down

0 comments on commit 8a271ae

Please sign in to comment.