Forum begins after the advertisement:


[Part 8] Item description overlapping problem

Home Forums Video Game Tutorial Series Creating a Metroidvania in Unity [Part 8] Item description overlapping problem

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #13926
    Anuk Thotawatta
    Level 5
    Participant
    Helpful?
    Up
    0
    ::

    when i exit inventory while hovering over something and re-enter the description stays until i hover over that same icon again and hover somewhere else.

    View post on imgur.com

    also will it be hard to select the items with keyboard like hollow knight

    #13930
    Joseph Tang
    Level 13
    Moderator
    Helpful?
    Up
    0
    ::

    For the item description, that’s because when you hover over an item, it’ll activate the item description panel To deactivate the item description, the event trigger is looking for your mouse exiting the item display. However, since the inventory is being closed, before that can happen, the item description is kept active in the inactive inventory menu. Thus, when you open it, the item description will still be open.

    If you want to stop this from happening, you need a way to deactivate the item description whenever you close the inventory.

    I haven’t tested it but i can say one way [I’m sure there are better ways] is to add an Update() method to the ItemDescription.cs to call for the Hide() method, or simply textDesc.SetActve = false;, whenever you let go of your inventory button.

    void Update()
        {
            if (Input.GetButtonUp("Inventory"))
            {
                textDesc.SetActve = false;
            }
        }
    #13975
    Anuk Thotawatta
    Level 5
    Participant
    Helpful?
    Up
    0
    ::

    my ItemDescription.cs looks like this and it doesnt work.

    <code>using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class ItemDescription : MonoBehaviour
    {
        // Start is called before the first frame update
        public GameObject textDesc;
        void Start()
        {
            textDesc.SetActive(false);
        }
        void Update(){
            if (Input.GetButtonUp("Inventory"))
            {
                textDesc.SetActive(false);
            }
        }
    
        // Update is called once per frame
        public void Show(){
            textDesc.SetActive(true);
        }
        public void Hide(){
            textDesc.SetActive(false);
        }
    }</code>

    And i found a new problem. my item descriptions don’t show when I’m in a scene with a checkpoint/bench

    View post on imgur.com
    #13977
    Joseph Tang
    Level 13
    Moderator
    Helpful?
    Up
    0
    ::

    Keeping the Code the same, you can use this instead for your PlayerController.cs:

    void ToggleInventory()
        {
            if (openInventory)
            {
                UIManager.Instance.inventory.SetActive(true);
            }
            else
            {
                StartCoroutine(InventoryCancelWait());
            }
        }
        IEnumerator InventoryCancelWait()
        {
            yield return new WaitForSecondsRealtime(0.01f);
            UIManager.Instance.inventory.SetActive(false);
        }

    We change the cancellation of the SetActive(false); for the inventory to a coroutine so that there will be time for the ItemDescription.cs to deactivate their text.

    As for your bench scene, make sure the scene has an EventSystem, which you can add by going to “GameObject > UI > EventSystem” An EventSystem will allow you to handle any event triggers such as a hovering mouse.

    #13981
    Anuk Thotawatta
    Level 5
    Participant
    Helpful?
    Up
    0
    ::

    adding the event system worked.

    but the description overlapping fix dident work. can i lock and turn off visibility of the mouse cursor when im outside the inventory?. i feel like that could work.

    #13982
    Joseph Tang
    Level 13
    Moderator
    Helpful?
    Up
    0
    ::
    void Update()
        {
            if (Input.GetButtonUp("Inventory"))
            {
                textDesc.SetActive(false);
            }
        }

    If you kept this in your ItemDescription.cs, it should work. You can also set the float in InventoryCancelWait() to a higher float to test it.

    Also, while you can turn your cursor on and off by setting up some code in your PlayerController.cs, it won’t fix the issue as the problem is you have no other way to turn off the item description without exiting your mouse off your item display.

    #13985
    Anuk Thotawatta
    Level 5
    Participant
    Helpful?
    Up
    0
    ::

    it finally worked. thank you so much

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: