using System.Collections; using System.Collections.Generic; using UnityEngine; using System; namespace Assets.Scripts { public class Chest : MonoBehaviour { bool gotItem; // Start is called before the first frame update void Start() { gotItem = false; } // Update is called once per frame void Update() { } public void interact(){ if (gotItem) { GameObject.Find("UIHandler").GetComponent().showMessage("ERROR;You already looted this chest"); } else { gameObject.transform.parent.Find("Lid").GetComponent().Play("ChestOpen"); Item item; int luck = GameObject.Find("Player").GetComponent().getStats()[11]; int type = new System.Random().Next(3); switch (type) { case 0: // Maybe add luck to increase chance for equipment item = new Equipment(luck); break; case 1: item = new Book(luck); break; default: item = new Item(luck); break; } GameObject.Find("Inventory").GetComponent().addItem(item); } gotItem = true; } } }