Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///////MANAGER
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class InventoryManager : MonoBehaviour
- {
- public GameObject SlotManager;
- public GameObject[] Slots;
- int allSlots;
- void Start()
- {
- allSlots = SlotManager.transform.childCount;
- Slots = new GameObject[allSlots];
- for (int i = 0; i < allSlots; i++)
- {
- Slots[i] = SlotManager.transform.GetChild(i).gameObject;
- Slots[i].gameObject.GetComponent<Slot>().Empty = true;
- }
- }
- void Update()
- {
- }
- public void PickUpItem(GameObject item)
- {
- Debug.Log("Item Recogido");
- for (int i = 0; i < allSlots; i++)
- {
- if (Slots[i].GetComponent<Slot>().Empty)
- {
- item.GetComponent<Item>().Pickup = true;
- Slots[i].GetComponent<Slot>().Empty = false;
- Slots[i].GetComponent<Slot>().objecto = item;
- Slots[i].GetComponent<Image>().sprite = item.GetComponent<Item>().ImageType;
- item.transform.parent = Slots[i].transform;
- return;
- }
- }
- }
- private void OnTriggerEnter(Collider cl)
- {
- if (cl.tag == "Item")
- {
- GameObject item = cl.gameObject;
- PickUpItem(item);
- }
- }
- }
- //////////////ITEMS
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public enum Items {
- Manzana,
- Hacha,
- Pan,
- Pico,
- Pistola
- };
- public class Item : MonoBehaviour
- {
- public Items tipo;
- public Sprite ImageType;
- public bool Pickup;
- void Start()
- {
- }
- void Update()
- {
- }
- void Use()
- {
- switch (tipo)
- {
- case Items.Hacha:
- {
- Debug.Log("Hacha");
- Destroy(this.gameObject);
- break;
- }
- case Items.Manzana:
- {
- Debug.Log("Manzana");
- Destroy(this.gameObject);
- break;
- }
- case Items.Pan:
- {
- Debug.Log("Pan");
- Destroy(this.gameObject);
- break;
- }
- case Items.Pico:
- {
- Debug.Log("Pico");
- Destroy(this.gameObject);
- break;
- }
- case Items.Pistola:
- {
- Debug.Log("Pistola");
- Destroy(this.gameObject);
- break;
- }
- }
- }
- public void OnClickObject()
- {
- Use();
- }
- }
- ///SLOTS
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.EventSystems;
- using UnityEngine.UI;
- public class Slot : MonoBehaviour, IPointerClickHandler
- {
- public bool Empty;
- public GameObject objecto;
- void Update()
- {
- if (objecto == null)
- {
- Empty = true;
- GetComponent<Image>().sprite = null;
- }
- else
- {
- Empty = false;
- }
- }
- public void OnPointerClick(PointerEventData pointerEventData)
- {
- Debug.Log("Slots Funcionando");
- objecto.GetComponent<Item>().OnClickObject();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement