So I want to make some inventory system for my game, and I found some issue when collecting the item, what I want here matching the index Inventory_UI system
exactly the same as currentIndex
on the collected item, then display it on Inventory_UI system
, let say I pickUp some item with the currentIndex = 1
so on Inventory_UI system
index=1
too and so on. this happening when inventory description to so the id
is same as itemIndex
picked up.
so here the the script:
- ItemManager( this for information of item ):
[System.Serializable] public class theItems { public string Name; public GameObject[] allCurrentPrefabs; public int numberOfIndex; public AudioClip[] allSound; public string[] terjemahannya; public string[] latinnya; } public class _ItemManager : MonoBehaviour { public static _ItemManager instance; private void Awake() { instance = this; } public List<theItems> items; [Header("SurahApa")] public int Surah; [Header("SoundStuff")] public AudioSource aSource; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { } public void PlaySurah(int surahnya, int ayatnya) { aSource.clip = items[surahnya].allSurahSound[ayatnya]; aSource.Play(); } }
- CollectibleItem ( this attach to each item )
public static _CollectibleAyat instance; private void Awake() { instance = this; } public enum InteractionType { none, pickUp, Examine } public InteractionType interactType; public int currentIndex; public string terjemahannya; public string latinnya; public GameObject allCurrentPrefabs; public UnityEvent customevent; public void Reset() { GetComponent<Collider2D>().isTrigger = true; } public void interact() { switch (interactType) { //case InteractionType.none: // Debug.Log("None"); // break; case InteractionType.Examine: _InteractSystem.instance.Examine(this); Debug.Log("Examine"); break; case InteractionType.pickUp: // Add the object to the pickUpItems List // Delete the Object _InventorySystem.instance.PickUpItem(gameObject); gameObject.SetActive(false); Debug.Log("PickingUp"); break; default: Debug.Log("Null Item"); break; } //Invoke (Call) the custom Event(s) customevent.Invoke(); }
- This InventorySystem( when item pickup)
public static _InventorySystem instance; private void Awake() { instance = this; } [Header("GeneralFields")] public List<GameObject> items = new List<GameObject>(); public bool isOpen; public int ayah; [Header("UI Items Section")] public GameObject UI_InventoryWindow; public Image[] item_Images; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.I)) { ToggleInventory(); } } public void ToggleInventory() { isOpen = !isOpen; UI_InventoryWindow.SetActive(isOpen); } public void PickUpItem(GameObject item) { items.Add(item); Update_UI(); } public void Update_UI() { HideAll(); for (int i = 0; i < items.Count; i++) { item_Images[i].sprite = items[i].GetComponent<SpriteRenderer>().sprite; item_Images[i].gameObject.SetActive(true); } } public void HideAll() { foreach (var i in item_Images) { i.gameObject.SetActive(false); } } //SampeSini public void ShowDescription(int id) { } public void HideDescription() { }
note: on the ShowDescription(int id)
i want to show item information what same as i picked up i have mentioned it above.