Hello everyone, I was having the same problem as others here before with a twist.
Currently my Inventory is being opened by scrolling down and closed by scrolling up. Using this little script I put together.
void Update()
{
if (Input.mouseScrollDelta.y < 0)
{
PlayerMenus.GetMenuWithName("Inventory").TurnOn();
}
if (Input.mouseScrollDelta.y > 0)
{
PlayerMenus.GetMenuWithName("Inventory").TurnOff();
}
}
For this to work I have my Inventory Appear Type set to manual. But closing it by scrolling just doesnt feel very intuitive and immersive. That's why I would also like it to be closed when the mouse leaves the area.
I tried some of the steps mentioned before and will continue to do so, but it seems like a fairly different scenario than the previous ones, so I leave this here.
I think my code above was flawed, as it wouldn't account for the mouse not initially being over the menu when first turned on. If what you have works, stick to it - but my corrected code is here:
Menu inventoryMenu;
bool isInsideMenu;
void Update()
{
if (inventoryMenu == null) inventoryMenu = PlayerMenus.GetMenuWithName ("Inventory");
if (inventoryMenu.IsOn ())
{
if (inventoryMenu.IsPointInside (KickStarter.playerInput.GetInvertedMouse ()))
{
isInsideMenu = true;
}
else if (isInsideMenu)
{
isInsideMenu = false;
inventoryMenu.TurnOff ();
}
}
else
{
if (Input.mouseScrollDelta.y < 0)
{
inventoryMenu.TurnOn ();
}
}
}
Comments
Hello everyone, I was having the same problem as others here before with a twist.
Currently my Inventory is being opened by scrolling down and closed by scrolling up. Using this little script I put together.
For this to work I have my Inventory Appear Type set to manual. But closing it by scrolling just doesnt feel very intuitive and immersive. That's why I would also like it to be closed when the mouse leaves the area.
I tried some of the steps mentioned before and will continue to do so, but it seems like a fairly different scenario than the previous ones, so I leave this here.
Any help would be greatly appreciated.
Welcome to the community, @Eldakan.
You can determine if the mouse is over a menu with:
Your script would probably need updating to something like:
thanks for your help and the welcome @ChrisIceBox!
I figured something out now using the function you gave me.
I didnt use the script you sent, because I am fairly new to C# and scripting in general so I didnt understand it well enough.
I used an other menu called InventoryOff and a boolean called InMenu and this script (for future help perhaps):
I think my code above was flawed, as it wouldn't account for the mouse not initially being over the menu when first turned on. If what you have works, stick to it - but my corrected code is here: