Forum rules - please read before posting.

Close inventory Menu on camera or scene change

I wondered if anyone had successfully written a script or extended some default actions to close or hide the inventory menu on a scene or camera change.

Maybe even after X seconds of inactivity (mouse not over) the inventory menu?

Thanks in advance

Comments

  • See the Manual's "Menu scripting" chapter for details on how to access and control Menus through scripting.

    You can hook into events to do react when AC performs common tasks. OnAfterChangeScene and OnSwitchCamera respectively for the first two.

    You can learn more about events from this tutorial.

    You can read the PlayerMenus component's IsMouseOverMenu() function to determine if the mouse is currently over a menu, and start a timer if not.

    Try this:

    using UnityEngine;
    using AC;
    
    public class TurnOffMenuExample : MonoBehaviour
    {
    
        public float mouseOverWaitTime = 5f;
        private float timer;
    
        private void OnEnable ()
        {
            EventManager.OnAfterChangeScene += OnAfterChangeScene;
            EventManager.OnSwitchCamera += OnSwitchCamera;
        }
    
        private void OnDisable ()
        {
            EventManager.OnAfterChangeScene -= OnAfterChangeScene;
            EventManager.OnSwitchCamera -= OnSwitchCamera;
        }
        private void Update ()
        {
            if (KickStarter.playerMenus.IsMouseOverMenu ())
            {
                timer = mouseOverWaitTime;
            }
            else if (timer > 0f)
            {
                timer -= Time.deltaTime;
                if (timer <= 0f)
                {
                    TurnOffMenu ();
                }
            }
        }
    
        private void OnSwitchCamera (_Camera old, _Camera newCamera, float transitionTime)
        {
            TurnOffMenu ();
        }
    
        private void OnAfterChangeScene ()
        {
            TurnOffMenu ();
        }
    
        private void TurnOffMenu ()
        {
            PlayerMenus.GetMenuWithName ("Inventory").TurnOff ();
        }
    
    }
    
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.