Forum rules - please read before posting.

Inventory box: Highlight after clicking on the object

Good evening Chris,
Hope you are well.
We are using latest AC version on Unity 2021.2.5f1.

We are trying to achieve something simple but we don't know how to do it. We want to use the highlight feature of the inventory after we click on it. Currently, it always shows the highlight. We noticed that on Inventory settings, we can add a SFX after we click, but not the highlight.
Let me show you in pictures what we need:

https://ibb.co/x74nY1D
https://ibb.co/fHpBF8J

The inventory is a notebook, that's why we want the circle to be drawn after we click.
Is it possible to do?

Thanks a lot!

Comments

  • It's down to the "rule" that dictates when the circle graphic should stop being drawn, but likely scripting will be involved.

    You can update the UI Button object in some way (e.g. enabling a Circle Image on a child object) when the user clicks by hooking into the OnMenuElementClick custom event. Something like this should do it, attached to each of the UI Button objects in the Canvas prefab:

    using UnityEngine;
    using UnityEngine.UI;
    using AC;
    
    public class InventoryCircle : MonoBehaviour
    {
    
        public Image image;
    
        private void OnEnable ()
        {
            EventManager.OnMenuElementClick += OnMenuElementClick;
            image.enabled = false;
        }
    
        private void OnDisable ()
        {
            EventManager.OnMenuElementClick -= OnMenuElementClick;
        }
    
        private void OnMenuElementClick (AC.Menu menu, MenuElement element, int slot, int buttonPressed)
        {
            MenuElement thisElement = menu.GetElementWithGameObject (gameObject);
            if (thisElement == element)
            {
                MenuInventoryBox inventoryBox = (MenuInventoryBox) element; 
                if (inventoryBox.uiSlots[slot].uiButton.gameObject == gameObject)
                {
                    image.enabled = true;
                }
            }
        }
    
    }
    
  • Thanks a lot Chris. We will give it a try soon and let you know if we are lost or something. Thanks a ton!

  • Hello Chris,
    We've tried a couple of hours for several workaround but no luck. First: this is not based on the UI, rather on the Inventory box. Those two "notepads" are two Inventory boxes. Second: I've tried the UI stuff but haven't found in which or what layer the Inventory Box is on... so the image was always behind :(

    I've read the whole "Menu Element" script and found the highlightTexture part, but I don't know how to make it only "on click". I also found the clickSound part, which was basically what I wanted, but couldn't pass the parametes to meet the critetra. Maybe from there I can add some line and make it work.

    Thanks a lot for the help!

  • this is not based on the UI, rather on the Inventory box. Those two "notepads" are two Inventory boxes

    You'll need to switch to Unity UI for this, but I recommend doing this anyway - AC-menus are really best for rapid prototyping.

    The AC-menu "Highlight texture" field is only intended for when an element is selected/clickable - not as a fixed texture while others are selected.

    This is not just a case of controlling when the circle is shown - but when it is hidden again. Using a custom script such as the above, with Unity UI, is the best way to control both.

    I've tried the UI stuff but haven't found in which or what layer the Inventory Box is on... so the image was always behind

    The image is at least enabling correctly, then?

    AC does not affect the layer/rendering options of any linked UI GameObjects beyond their basic on/off visibility. Ensuring that the circle is drawn atop the regular Button is a case of moving it to the correct position in the Hierarchy - typically above it.

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.