Hello everyone, this question can be a bit complicated
I have a GUI that contains slots that you can put items inside. Each item represents a scriptable object.
Whenever a new item is dropped in the slot, the slot manager then gets the items stored on each slot and saves it in its own variables.
Everything works, but the items didn’t show up on the manager code. It only shows up when I stopped the game.
I have a video to show you what I mean:
CODES:
1 SlotDrop_Handler (storing the item dragged into the slot)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class SlotDrop_Handler : MonoBehaviour, IDropHandler {
public Inventory_Controller inventory;
public PowerCore_Controller powercoreControl;
public Item currentItem = null;
public List<Item> itemList;
public GameObject slot{
get{
if(transform.childCount > 0){
return transform.GetChild(0).gameObject;
}else{
return null;
}
}
}
public void OnDrop(PointerEventData eventData){
if(slot.GetComponent<Image>().sprite == null){
Item draggedObject = eventData.pointerDrag.GetComponentInParent<Inventory_Slot>().item;
inventory.RemoveItemFromList(draggedObject);
currentItem = draggedObject;
Debug.Log("Combining with " + draggedObject.name);
for (int i = 0; i < itemList.Count; i++)
{
if(itemList*.name == draggedObject.name){*
_ slot.GetComponent().sprite = itemList*.icon;_
_ slot.GetComponent().enabled = true;_
_ break;*_
* }*
* }*
* powercoreControl.CallCombinationManager();*
* }*
* }*
* }*
2 PowerCore_Controller (calls the combination manager to check for new items in each slot)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PowerCore_Controller : MonoBehaviour {
* public GameObject currentPowercore = null;*
* public PowerCore powercoreObject;*
* public GameObject crosshair, textMessage;*
* public GameObject basicLayout;*
* public List powerCores;*
* void Start(){*
* UpdatePowerCore();*
* }*
* public void PickupPowerCore(PowerCore powercorepickup){*
* currentPowercore = powercorepickup.referenceObject;*
* powercoreObject = powercorepickup;*
* UpdatePowerCore();*
* }*
* public void UpdatePowerCore(){*
* if(currentPowercore == null){*
* crosshair.SetActive(false);*
* textMessage.SetActive(true);*
* return;*
* } else {*
* Debug.Log(“Update Power Core”);*
* crosshair.SetActive(true);*
* textMessage.SetActive(false);*
* DisableAllCores();*
* string findCore = currentPowercore.name;*
* for (int i = 0; i < powerCores.Count; i++){*
_ if(findCore == powerCores*.name){*_
_ powerCores*.SetActive(true);
break;*_
* }*
* }*
* {*
* }*
* }*
* }*
* //Call relevant combination manager to update combination*
* public void CallCombinationManager(){*
* currentPowercore.GetComponent<CoreCombination_Manager>().UpdateCombination(this, basicLayout);*
* }*
* void DisableAllCores(){*
* for (int i = 0; i < powerCores.Count; i++)*
* {*
_ powerCores*.SetActive(false);*_
* }*
* }*
}
3 CoreCombination_Manager (gets the variables from the layout handler to store)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CoreCombination_Manager : MonoBehaviour {
* [Header(“Basic Layout”)]*
* public Item basicPrimary;*
* public Item basicSecondary, basicPassive;*
* void Start(){*
* ResetCombinations();*
* }*
* public void UpdateCombination(PowerCore_Controller powercoreControl, GameObject layout){*
* if(powercoreControl.currentPowercore.name == “BasicCore - 0”){*
* layout.GetComponent<Layout_Handler>().GetBasicCombinations(this);
_ Debug.Log(“Get Basic Combinations”);*_
* ResetCombinations();*
* if(basicPrimary == null){*
* basicPrimary = layout.GetComponent<Layout_Handler>().primaryItem;
_ }
if(basicSecondary == null){_
basicSecondary = layout.GetComponent<Layout_Handler>().secondaryItem;
_ }
if(basicPassive == null){_
basicPassive = layout.GetComponent<Layout_Handler>().passiveItem;
_ }
}*_
* }*
* void ResetCombinations(){*
* basicPrimary = null;*
* basicPassive = null;*
* basicSecondary = null;*
* }*
}
Last but not least, 4 Layout_Handler (Goes through each slot and stores the item stored in the slot)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Layout_Handler : MonoBehaviour {
* public Item primaryItem, secondaryItem, passiveItem;*
* public void GetBasicCombinations(CoreCombination_Manager combinationManager){*
* int allExceptLast = transform.childCount - 1;*
* for (int i = 0; i < allExceptLast; i++)*
* {*
* GameObject slot = transform.GetChild(i).gameObject;*
* if(slot.name == “PrimarySlot”){*
* if(slot.GetComponent<SlotDrop_Handler>().currentItem != null){
primaryItem = slot.GetComponent<SlotDrop_Handler>().currentItem;
Debug.Log("basicPrimary is now " + slot.GetComponent<SlotDrop_Handler>().currentItem.name);
_ }else{
combinationManager.basicPrimary = null;
}*_
* }else if (slot.name == “SecondarySlot”){*
* if(slot.GetComponent<SlotDrop_Handler>().currentItem != null){
secondaryItem = slot.GetComponent<SlotDrop_Handler>().currentItem;
Debug.Log("basicSecondary is now " + slot.GetComponent<SlotDrop_Handler>().currentItem.name);
_ }else{
combinationManager.basicSecondary = null;
}*_
* }else if (slot.name == “PassiveSlot”){*
* if(slot.GetComponent<SlotDrop_Handler>().currentItem != null){
passiveItem = slot.GetComponent<SlotDrop_Handler>().currentItem;
Debug.Log("basicPassive is now " + slot.GetComponent<SlotDrop_Handler>().currentItem.name);
_ }else{
combinationManager.basicPassive = null;
}*_
* }*
* }*
* }*
}
This has been very long, but I hope I’ve provided enough details to help you help me. What am I saying. But anywho, thank you in advance.