-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vendor.cs
41 lines (35 loc) · 987 Bytes
/
Vendor.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Vendor : MonoBehaviour {
Currency script;
Inventory invScript;
public GameObject vendorUI;
public int cost;
void Start()
{
vendorUI.SetActive(false);
script = GameObject.FindWithTag("GameController").GetComponent<Currency>();
invScript = GameObject.FindWithTag("GameController").GetComponent<Inventory>();
}
void OnTriggerEnter()
{
vendorUI.SetActive(true);
Cursor.visible = true;
}
// Update is called once per frame
void OnTriggerExit ()
{
vendorUI.SetActive(false);
Cursor.visible = false;
}
public void BuyItem(GameObject objToCreate)
{
if (script.gold >= cost)
{
script.gold -= cost;
GameObject i = Instantiate(objToCreate);
i.transform.SetParent(invScript.invTab.transform);
}
}
}