Home>

I want to display the acquired items on the UI in order and delete them in the order of first-in first-out after a certain time has elapsed
When you get an item, the UI displays "You got XX", and at that time you store the item object name with Stack.Push, and after a certain amount of time has passed, the order that you retrieve it with Stack.Pop. I'd like to delete the UI, but I can't make a successful flow of deleting it by detecting the bool of the UI after a certain period of time at Pop.

// Program for UI that processed for a certain period of time
    [Header ("UI stuff to change")]
    [SerializeField] private Text itemNameText;
    [SerializeField] private Text itemNumberHeld;
    [Header ("TextScroll")]
    [SerializeField] private float textScrollSpeed;
    [SerializeField] private float limitPosition;
    [Header ("TextTransparent")]
    [SerializeField] private float itemName;
    [SerializeField] private float itemNumber;
    [SerializeField] private float transparetnSpeed;
    [Header ("InActiveBool")]
    public bool inActive = false;
    private void Update ()
    {
        if (itemNameText.transform.position.y<= limitPosition&&
            itemNumberHeld.transform.position.y<= limitPosition)
        {
            itemNameText.transform.position = new Vector2 (itemNameText.transform.position.x,
                itemNameText.transform.position.y + textScrollSpeed ​​* Time.deltaTime);
            itemNumberHeld.transform.position = new Vector2 (itemNumberHeld.transform.position.x,
                itemNumberHeld.transform.position.y + textScrollSpeed ​​* Time.deltaTime);
            if (itemNameText.transform.position.y>= 450 ||
               itemNumberHeld.transform.position.y>= 450)
            {
                if (itemName! = 0&&itemNumber! = 0)
                {
                    //Debug.Log("Start ");
                    itemNameText.color = new Color (1, 1, 1, itemName);
                    itemNumberHeld.color = new Color (1, 1, 1, itemNumber);
                    itemName-= transparetnSpeed ​​* Time.deltaTime;
                    itemNumber-= transparetnSpeed ​​* Time.deltaTime;
                }
            }
        }
        if (itemNumberHeld.transform.position.y>= limitPosition ||
           itemNumber<= 0)
        {
            inActive = true;
        }
    }
// UI display and object name storage program
[Header ("GetItem Information")]
    [SerializeField] private GameObject blankGetItemSlot;// Item
    [SerializeField] private GameObject inventoryPanel;// Display item name in the frame
    public GetItemInventory getItemInventory;
    Stack<GameObject>stack = new Stack<GameObject>() {};
    private void OnEnable ()
    {
        MakeGetItemSlots ();
    }
    void MakeGetItemSlots ()
    {
        if (getItemInventory)
        {
            for (int i = 0;i<getItemInventory.myGetItemInvenotory.Count;i ++)
            {
                if (getItemInventory.myGetItemInvenotory [i] .numberHeld>0 ||
                    getItemInventory.myGetItemInvenotory [i] .itmeName == "Bottle")
                {
                    GameObject temp = Instantiate (blankGetItemSlot, inventoryPanel.transform.position, Quaternion.identity);
                    temp.transform.SetParent (inventoryPanel.transform);
                    GetItemSlot newSlot = temp.GetComponent<GetItemSlot>();
                    if (newSlot)
                    {
                        newSlot.SetUp (getItemInventory.myGetItemInvenotory [i], this);
                        stack.Push (temp);
                        Debug.Log (getItemInventory.myGetItemInvenotory [i]);
                        if (newSlot.inActive)
                        {
// If GetItemSlot newSlot is true from the beginning, it will be deleted immediately
// It can not be done because it is a process after a certain time
                            stack.Pop ();
                            Destroy (temp);
                            Debug.Log (getItemInventory.myGetItemInvenotory [i]);
                        }
                    }
                }
            }
        }
    }


  • Answer # 1

    While analyzing what cannot be done, it is determined that Stack is not bad.
    Once again, I was able to successfully process by creating an array when I got the item in the function and executing it.