Discussions
Sign In
Forum rules
- please read before posting.
How to check if an item is selected?
valter
October 2017
in
Technical Q&A
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
ChrisIceBox
October 2017
edited October 2017
See the "Inventory scripting" chapter of the Manual - the currently-selected item can be read with:
KickStarter.runtimeInventory.selectedItem;
valter
October 2017
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?
ChrisIceBox
October 2017
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;
}
}
valter
October 2017
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!
Sign In
Register
Quick Links
Categories
Recent Discussions
Categories
12.6K
All Categories
66
Official news
1.5K
Engine development
10.6K
Technical Q&A
337
Games showcase
151
Extending the editor
229
Adventure talk
Welcome to the official forum for Adventure Creator.
Forum rules
Main website
Store page
Community wiki
Community Discord
Powered by Vanilla
Comments
KickStarter.runtimeInventory.selectedItem;
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;
}
}