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
- This topic has 6 replies, 2 voices, and was last updated 8 months ago by Anuk Thotawatta.
-
AuthorPosts
-
April 17, 2024 at 9:27 pm #13926::
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
April 17, 2024 at 11:00 pm #13930::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 theHide()
method, or simplytextDesc.SetActve = false;
, whenever you let go of your inventory button.void Update() { if (Input.GetButtonUp("Inventory")) { textDesc.SetActve = false; } }
April 18, 2024 at 7:31 pm #13975::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
April 18, 2024 at 7:51 pm #13977::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.
April 18, 2024 at 8:55 pm #13981::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.
April 18, 2024 at 8:59 pm #13982::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.
April 19, 2024 at 12:35 am #13985 -
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: