hello so tldr to keep items persistence in my project I’ve attached a dontdestroy script to them my problem arises from the fact I can pick one test item up in the room and it shows up the first inventory slot but as I go to the door and load a new scene turn around and go back to the item room and try picking the other test item up it does not show up in the 2nd inventory slot as intended I’ve don’t some debugging its not the pickup script but its the OnpickupItem function in my script
help would be appreciated as I have no clue on what to due
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.EventSystems;
using FMODUnity;
public class InventorySelectController : MonoBehaviour
{
[SerializeField] private GameObject _inventoryView;
[SerializeField] private TMP_Text _itemNameText;
[SerializeField] private TMP_Text _itemDescriptionText;
[SerializeField] private EventReference OpenInventorySound;
[SerializeField] private EventReference CloseInventorySound;
[SerializeField] private List<ItemSlot> _slots;
[SerializeField] private Playermovement _Playermovement;
[SerializeField] private ScreenFader _fader;
private enum State
{
menuClosed,
menuOpen,
};
private State _state;
private void OnEnable()
{
EventBus.Instance.onPickUpItem += OnItemPickedUp;
}
private void OnDisable()
{
EventBus.Instance.onPickUpItem -= OnItemPickedUp;
}
private void OnItemPickedUp(ItemData itemData)
{
foreach (var slot in _slots)
{
if (slot.isEmpty())
{
slot.itemData = itemData;
Debug.Log("slot has been filled");
break;
}
}
}
public void OnSlotSelected(ItemSlot selectedSlot)
{
if (selectedSlot.itemData == null)
{
_itemNameText.ClearMesh();
_itemDescriptionText.ClearMesh();
return;
}
_itemNameText.SetText(selectedSlot.itemData.Name);
_itemDescriptionText.SetText(selectedSlot.itemData.Description[0]);
if (selectedSlot == null)
{
Debug.Log("slot selected");
}
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.Tab))
{
if (_state == State.menuClosed)
{
EventBus.Instance.PauseGamePlay();
Debug.Log(_state);
_fader.FadeToBlack(0.3f, FadeFromMenuCallback);
_state = State.menuOpen;
}
else if (_state == State.menuOpen)
{
EventBus.Instance.ResumeGamePlay();
Debug.Log(_state);
_fader.FadeToBlack(0.3f, FadeToMenuCallback);
_state = State.menuClosed;
}
}
}
private void FadeFromMenuCallback()
{
AudioManager.instance.PlayOneShot(OpenInventorySound, this.transform.position);
_inventoryView.SetActive(true);
_fader.FadeFromBlack(0.3f, null);
//Debug.Log(_state);
}
private void FadeToMenuCallback()
{
AudioManager.instance.PlayOneShot(OpenInventorySound, this.transform.position);
_inventoryView.SetActive(false);
_fader.FadeFromBlack(0.3f, null);
//Debug.Log(_state);
}
}