Quit Button not closing the shop

When testing with print statements the script does reach the statement:
shopper.SetActiveShop(null);
for closing down the shop in the Close method in the ShopUI script.

Additional checks show that everything leads to the shopper script so i am trying to see if I am missing something there but everything looks set correctly.

The Quit Button OnClick event is setup connected to the ShopUI then calling the ShopUI,Close function.
I know it works as it will call the print(“Close”); statement I made to test. So I think something is not calling in Shopper.

namespace RPG.Shops
{
    public class Shopper : MonoBehaviour
    {
        Shop activeShop = null;

        public event Action activeShopChange;

        public void SetActiveShop(Shop shop)
        {
            activeShop = shop;
            if (activeShop != null)
            {
                activeShopChange();
            }
        }

        public Shop GetActiveShop()
        {
            return activeShop;
        }
    }
}

You are only firing the event if the activeShop is not null. The code that closes the shop UI is run when the event fires so you need to always fire the event

    public void SetActiveShop(Shop shop)
    {
        activeShop = shop;
        activeShopChange();
    }
1 Like

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

Privacy & Terms