Simple Buy Item Logic
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Item : MonoBehaviour
|
||||
{
|
||||
public Sprite sprite;
|
||||
public Type type;
|
||||
|
||||
public int Cost
|
||||
{
|
||||
get
|
||||
{
|
||||
return cost;
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField] private int cost;
|
||||
|
||||
public enum Type
|
||||
{
|
||||
Mushroom = 0, DoubleDice = 1
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b369e867ce7bd2944baef65e2537086c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,22 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class UIItem : MonoBehaviour
|
||||
{
|
||||
public Item item;
|
||||
|
||||
public void BuyItem()
|
||||
{
|
||||
Player player = ItemShop.currentPlayer;
|
||||
|
||||
if (player.coins - item.Cost >= 0)
|
||||
{
|
||||
player.AddCoins(-item.Cost);
|
||||
UIHandler.GetInstance().ButtonBack();
|
||||
player.AddItem(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2133c87b176066c42bf8ebee13208124
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user