/
BasicUI.cs
59 lines (58 loc) · 1.91 KB
/
BasicUI.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
51
52
53
54
55
56
57
58
59
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class BasicUI : MonoBehaviour
{
void OnGUI()
{
int posX = 10;
int posY = 10;
int width = 100;
int height = 30;
int buffer = 10;
List<string> itemList = Managers.Inventory.GetItemList();
if (itemList.Count == 0)
{
GUI.Box(new Rect(posX, posY, width, height), "No Items");
}
foreach (string item in itemList)
{
int count = Managers.Inventory.GetItemCount(item);
Texture2D image = Resources.Load<Texture2D>("Icons/" + item);
GUI.Box(new Rect(posX, posY, width, height),
new GUIContent("(" + count + ")",
image));
posX += width + buffer;
}
string equipped = Managers.Inventory.equippedItem;
if (equipped != null)
{
posX = Screen.width - (width + buffer);
Texture2D image =
Resources.Load("Icons/" + equipped) as Texture2D;
GUI.Box(new Rect(posX, posY, width, height),
new GUIContent("Equipped", image));
}
posX = 10;
posY += height + buffer;
foreach (string item in itemList)
{
if (GUI.Button(new Rect(posX, posY, width, height),
"Equip " + item))
{
Managers.Inventory.EquipItem(item);
}
if (item == "health")
{
if (GUI.Button(new Rect(posX, posY + height + buffer, width,
height), "Use Health"))
{
Managers.Inventory.ConsumeItem("health");
Managers.Player.IncreaseHealth(5);
GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerCharacter>().heal(5);
}
}
posX += width + buffer;
}
}
}