Item shop functioning
This commit is contained in:
@@ -9,8 +9,8 @@ using UnityEngine.UI;
|
||||
public class GameManager : MonoBehaviour
|
||||
{
|
||||
public TMP_Text usernameTxt;
|
||||
public TMP_Text coinsTxt;
|
||||
public TMP_Text gemsTxt;
|
||||
public TMP_Text[] coinsTxt;
|
||||
public TMP_Text[] gemsTxt;
|
||||
public TMP_Text metalTxt;
|
||||
public TMP_Text oxygenTxt;
|
||||
public TMP_Text levelTxt;
|
||||
@@ -37,8 +37,12 @@ public class GameManager : MonoBehaviour
|
||||
}
|
||||
|
||||
public void RefreshData(){
|
||||
coinsTxt.text = DBmanager.Coins.ToString();
|
||||
gemsTxt.text = DBmanager.Gems.ToString();
|
||||
foreach(TMP_Text txt in coinsTxt){
|
||||
txt.text = DBmanager.Coins.ToString();
|
||||
}
|
||||
foreach(TMP_Text txt in gemsTxt){
|
||||
txt.text = DBmanager.Gems.ToString();
|
||||
}
|
||||
metalTxt.text = DBmanager.Metal.ToString();
|
||||
oxygenTxt.text = DBmanager.Oxygen.ToString();
|
||||
levelTxt.text = Mathf.CeilToInt(DBmanager.Level).ToString();
|
||||
|
||||
47
Assets/Game/Scripts/ItemShop.cs
Normal file
47
Assets/Game/Scripts/ItemShop.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
using UnityEngine.UI;
|
||||
public class ItemShop : MonoBehaviour
|
||||
{
|
||||
public ShopItemData selectedItem;
|
||||
|
||||
public Image itemImage;
|
||||
public TMP_Text itemTxt;
|
||||
public TMP_Text levelTxt;
|
||||
|
||||
public TMP_Text statTxt;
|
||||
public TMP_Text priceTxt;
|
||||
public TMP_Text gemTxt;
|
||||
|
||||
public Button buyBtn;
|
||||
|
||||
void Start(){
|
||||
SelectShopItem(selectedItem);
|
||||
}
|
||||
|
||||
public void SelectShopItem(ShopItemData selected){
|
||||
selectedItem = selected;
|
||||
|
||||
if(selectedItem==null){Debug.LogError("Null shop item selected, Please check this"); return;}
|
||||
|
||||
itemImage.sprite = selectedItem.image;
|
||||
itemTxt.text = selectedItem.itemName;
|
||||
statTxt.text = selectedItem.stat.ToString();
|
||||
priceTxt.text = selectedItem.price.ToString();
|
||||
gemTxt.text = selectedItem.gems.ToString();
|
||||
|
||||
buyBtn.interactable = selectedItem.price < DBmanager.Coins && selectedItem.gems < DBmanager.Gems;
|
||||
}
|
||||
|
||||
public void BuySelected(){
|
||||
if(selectedItem == null){
|
||||
Debug.LogError("Cant buy, No item is selected");
|
||||
return;
|
||||
}
|
||||
|
||||
DBmanager.SetCoins(DBmanager.Coins - selectedItem.price);
|
||||
DBmanager.SetGems(DBmanager.Gems- selectedItem.gems);
|
||||
}
|
||||
}
|
||||
11
Assets/Game/Scripts/ItemShop.cs.meta
Normal file
11
Assets/Game/Scripts/ItemShop.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 74b5944a58fcb8dc5943aa171c380e91
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
13
Assets/Game/Scripts/ShopItemData.cs
Normal file
13
Assets/Game/Scripts/ShopItemData.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[CreateAssetMenu(fileName = "ShopItem", menuName = "GameData/ShopItemData", order = 1)]
|
||||
public class ShopItemData : ScriptableObject
|
||||
{
|
||||
public string itemName;
|
||||
public int price;
|
||||
public int gems;
|
||||
public int stat;
|
||||
public Sprite image;
|
||||
}
|
||||
11
Assets/Game/Scripts/ShopItemData.cs.meta
Normal file
11
Assets/Game/Scripts/ShopItemData.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b98fd43ffe0dd7235a6e6b3ab35e9d33
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
@@ -28,6 +27,11 @@ public class WorldItemSelector : MonoBehaviour
|
||||
if(Selector.insideHall){
|
||||
HumanInteractor interactor = hit.collider.GetComponent<HumanInteractor>();
|
||||
Selector.selectHuman(interactor);
|
||||
|
||||
WorldspaceButton button = hit.collider.GetComponent<WorldspaceButton>();
|
||||
if(button!=null){
|
||||
button.Click();
|
||||
}
|
||||
}
|
||||
}else{
|
||||
Selector.selectBuilding(null);
|
||||
|
||||
23
Assets/Game/Scripts/WorldspaceButton.cs
Normal file
23
Assets/Game/Scripts/WorldspaceButton.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class WorldspaceButton : MonoBehaviour
|
||||
{
|
||||
public UnityEvent OnClick;
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Click(){
|
||||
OnClick.Invoke();
|
||||
}
|
||||
}
|
||||
11
Assets/Game/Scripts/WorldspaceButton.cs.meta
Normal file
11
Assets/Game/Scripts/WorldspaceButton.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ea297f5ed36238072a08f95df582ae09
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user