Shows an alertScreen when dropping item

What is the best practice to add an altertPopup when dropping an item? Players can click yes to drop or click no to cancel. Should I make a new canvas with two buttons? when dragging item outside of the inventory area, it triggers to “show” the canvas UI instead of dropping item function? instead, hookup the dropping function to the canvas UI, so it will get triggers when clicking yes? If this is the correct logic, should I create a new script with a drop function that connect to this public void dropping function? or I just simply hookup this ItemDropper script to the new UI prefab? and write all the hide show UI code in this ItemDropper script?

In addition, do unity have a lot of external libraries (similar to pub, cocopods. etc.) that can make development more efficient? cause I don’t see a lot of unity function libraries from GitHub. is there a unity library pool like pub.dev for flutter dart, or cocopod for swift?

We’ll start with the last question first. There are a few external sources for libraries outside of Unity… check out OpenUpm.com. I normally don’t point students in this direction, but you do appear familiar with some of the other development libraries out there. There’s a bit of installation involved to use the OpenUPM manager, or you can add packages to the manifest by creating a scoped registry and adding the dependency.

I think you’re on the right track with the window. Set up a GameObject with a Confirm and Cancel button.

Your confirmation class will need a reference to the Player’s Inventory as well as the Player’s RandomItemDropper. You’ll also want a global variable with the item and quantity being “dropped”

[SerializeField] GameObject window;
InventoryItem itemToDrop=null;
int quantity = 0;

public void ConfirmTransaction(InventoryItem item, int number = 1)
{
     itemToDrop = item;
     quantity = number;
     window.SetEnabled(true);
}

public void CancelTransaction()
{
     inventory.AddToFirstEmptySlot(itemToDrop, quantity);
     itemToDrop=null;
     quantity=0;
}

public void ConfirmTransaction()
{
    itemDropper.DropItem(itemToDrop, quantity);
    itemToDrop=null;
    quantity=0;
}

Then just wire up your Confirm and Cancel buttons appropriately.

Thanks Brian.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms