52 lines
No EOL
968 B
C#
52 lines
No EOL
968 B
C#
using UnityEngine;
|
|
using System.Collections;
|
|
using UnityEngine.UI;
|
|
|
|
|
|
public class Inventory : MonoBehaviour
|
|
{
|
|
public Image[] itemImages = new Image[numItemSlots];
|
|
public Item[] items = new Item[numItemSlots];
|
|
public const int numItemSlots = 25;
|
|
|
|
private static bool created = false;
|
|
|
|
void Awake()
|
|
{
|
|
if (!created)
|
|
{
|
|
DontDestroyOnLoad(this.gameObject);
|
|
created = true;
|
|
}
|
|
}
|
|
|
|
public void AddItem(Item itemToAdd)
|
|
{
|
|
for (int i = 0; i < items.Length; i++)
|
|
{
|
|
if (items[i] == null)
|
|
{
|
|
items[i] = itemToAdd;
|
|
itemImages[i].sprite = itemToAdd.sprite;
|
|
itemImages[i].enabled = true;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void RemoveItem (Item itemToRemove)
|
|
{
|
|
GameObject instance = (GameObject)Instantiate(Resources.Load(itemToRemove.name));
|
|
|
|
for (int i = 0; i < items.Length; i++)
|
|
{
|
|
if (items[i] == itemToRemove)
|
|
{
|
|
items[i] = null;
|
|
itemImages[i].sprite = null;
|
|
itemImages[i].enabled = false;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
} |