Forum rules - please read before posting.

How to check if an item is selected?

How can I check from scripts if any inventory item is selected? 

void Update () {

  if (Input.GetMouseButtonDown (1)) {
    if (isItemSelected?) {
      [my code]
    }
  }

}

No matter what item but only if at the right click an item is selected.
Thanks.

Comments

  • edited October 2017
    See the "Inventory scripting" chapter of the Manual - the currently-selected item can be read with:

    KickStarter.runtimeInventory.selectedItem;
  • edited October 2017
    Yes, I had already tried it without success.
    if (KickStarter.runtimeInventory.selectedItem != null) did not work
    but I understand the reason.
    I'm inside the GetItemClick Custom Event and when I right-click to deselect the item it occurs before reading SelectedItem in Update (). Indeed

    void Update () {

       if (Input.GetMouseButtonDown (1)) {
         Debug.Log (KickStarter.runtimeInventory.SelectedItem);
         if (KickStarter.runtimeInventory.SelectedItem! = null) {
           [my code]
         }
       }

    }

    Debug.Log already returns null.
    For this reason in the other post I asked how to intercept the mouse click.
    Can you suggest how to read the right mouse button before the Deselect Item is executed?

  • edited October 2017
    There is no GetItemClick custom event - what are you referring to?

    If you're running this all in Update anyway, you can just read the selected item and store it in a temporary variable:

    InvItem lastSelectedItem;
    void Update ()
    {
      if (KickStarter.runtimeInventory.SelectedItem != null)
      {
        lastSelectedItem = KickStarter.runtimeInventory.SelectedItem;
      }
    }

  • Sorry, OnMenuElementClick custom event, GetItemClick was my function.
    It seems, however, that I have solved with custom input overrides which we have spoken in another post.
    Thank you

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.
Do NOT follow this link or you will be banned from the site!