-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShopItem.cs
50 lines (40 loc) · 1.03 KB
/
ShopItem.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using Platypus;
using UnityEngine;
using System.Collections;
public class ShopItem : UsableActivated {
public int Cost = 100;
public string ItemType = "item";
public string ItemKey = "item";
bool available = true;
TextMesh costText;
SpriteRenderer icon;
public AudioSource BuySound;
public AudioSource NotEnoughCoinsSound;
void Start(){
costText = transform.FindChild("cost").GetComponent<TextMesh>();
costText.text = Cost.ToString();
icon = transform.FindChild("icon").GetComponent<SpriteRenderer>();
if (Inventory.GetInstance().HasItem(ItemType, ItemKey))
{
Hide();
}
}
public override void Activate(GameObject player){
if (available)
{
var success = Inventory.GetInstance().BuyItem(Cost, ItemType, ItemKey);
if (success)
{
Hide();
BuySound.Play();
return;
}
}
NotEnoughCoinsSound.Play();
}
void Hide(){
available = false;
costText.gameObject.SetActive(false);
icon.gameObject.SetActive(false);
}
}