Forum rules - please read before posting.

Display picked up item's name?

Hello everyone,

is there a way to display the item's name you found/pick up? I've made a pop-up menu with an action script to say"Item Found: Item name goes here" but I can't seem to work out how to show it. I'm guessing a custom script may be in order.

Any help would be greatly appreciated :)

Comments

  • Yes - not a complex one, but one is necessary to initialise the Menu with the necessary data:

    using UnityEngine;
    using AC;
    
    public class NewItemMenuSetup : MonoBehaviour
    {
    
        private const string menuName = "NewItem";
        private const string nameElement = "ItemName";
        private const string graphicElement = "ItemGraphic";
    
        private void OnEnable () { EventManager.OnInventoryAdd += OnInventoryAdd; }
        private void OnDisable () { EventManager.OnInventoryAdd -= OnInventoryAdd; }
    
        private void OnInventoryAdd (InvItem invItem, int count)
        {
            Menu newItemMenu = PlayerMenus.GetMenuWithName (menuName);
    
            MenuLabel itemNameLabel = newItemMenu.GetElementWithName (nameElement) as MenuLabel;
            itemNameLabel.label = invItem.GetLabel (Options.GetLanguage ());
            itemNameLabel.UpdateLabelText ();
    
            if (!string.IsNullOrEmpty (graphicElement))
            {
                MenuGraphic itemGraphic = newItemMenu.GetElementWithName (graphicElement) as MenuGraphic;
                itemGraphic.SetNormalGraphicTexture (invItem.tex);
            }
            newItemMenu.TurnOn ();
        }
    
    }
    

    This is adapted from the NewItemMenuSetup script in the Chamber demo over on the Downloads page, so check that out to see how its NewItem menu is set up. Essentially though, it's a Menu named NewItem that features a Label named ItemName, and (optionally) a Graphic named ItemGraphic.

    When an item is added to the Player's Inventory, the elements are updated with that item's name/icon, and the Menu is turned on.

  • Thanks again for that Chris! Really appreciate the help and loving AC!

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.