Forum rules - please read before posting.

Inventory Close When Cursor at positions Left, Right, Above and Below Inventory Box

Hi Chris,

So you wonderfully helped me close the inventory bar when the cursor went above a certain height on screen using this code:

    using AC;
    using UnityEngine;

    public class CloseInventoryOnOver : MonoBehaviour
    {
        public AC.ActionListAsset actionListToRun;

        private void Update ()
        {
            Vector2 mousePosition = Input.mousePosition;
            if (PlayerMenus.GetMenuWithName ("SleepytimeVillageInventory").IsOn () || (PlayerMenus.GetMenuWithName ("RealWorldInventory").IsOn ()) )
            { 
                if (mousePosition.y > 0.20f * Screen.height)
                {
                    PlayerMenus.GetMenuWithName ("SleepytimeVillageInventory").TurnOff ();
                    PlayerMenus.GetMenuWithName ("RealWorldInventory").TurnOff ();

                    actionListToRun.Interact();
                }
            }
        }
        }

How do I change this code so that the inventory closes at position to the left, r, above and below?

See screenshot, thanks!

https://www.dropbox.com/s/z52cca97su8c3p7/InventoryClose2.png?dl=0

Comments

  • As in, when outside of the white box?

    You can make multiple checks of the same kind:

    if (mousePosition.y > 0.8f * Screen.height ||
        mousePosition.y < 0.2f * Screen.height ||
        mousePosition.x < 0.2f * Screen.width ||
        mousePosition.x > 0.8f * Screen.width)
    

    However, you can also make use of the PlayerMenu's MouseOverMenu property:

    if (KickStarter.playerMenus.MouseOverMenu == null)
    
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.