using System.Collections.Generic; using UnityEngine; public class PlayerController : MonoBehaviour { #region Singleton public static PlayerController instance; private void Awake() { if(instance != null) { Debug.LogWarning("More than one instance of PlayeController found"); } instance = this; } #endregion public Dictionary inventory; public readonly int inventorySpace = 28; private int money; private UsableItem selectedItem; public int startMoney = 100; // Start is called before the first frame update void Start() { inventory ??= new Dictionary(); money = startMoney; } // Update is called once per frame void Update() { } public void setSelectedItem(UsableItem item) { if(inventory.ContainsKey(item)) { selectedItem = item; Cursor.SetCursor(item.defaultSprite.texture, Vector2.zero, CursorMode.Auto); } else { Debug.Log("An item requested to select isn't in the inventory" + item); } } public delegate void onItemChanged(); public onItemChanged onItemChangedCallback; public void addItem(Item item, int amount) { if(inventory.Count >= inventorySpace) { Debug.Log("Not enough inventory space!"); return; } inventory.Add(item, amount); onItemChangedCallback?.Invoke(); } public void removeItem(Item item, int amount) { inventory.Add(item, -amount); onItemChangedCallback?.Invoke(); } }