Friday, August 19, 2022
HomeGame Developmentunity - Objects bought not Showing within the stock once they're bought

unity – Objects bought not Showing within the stock once they’re bought


I buy Objects from my store menu In-Sport it would not present in my Stock these are the images from the sport store and when i buy one thing and when i open the stock menu:

Opening Shop menu to buy an Item

When i purchase the item and the money is subtracted from my Coins text

Empty Inventory Menu after purchase

These are the scripts I am utilizing for the Stock and the store:

Store Supervisor

utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;
utilizing UnityEngine.EventSystems;
utilizing UnityEngine.UI;
utilizing UnityEngine.GameFoundation;

public class ShopManager : MonoBehaviour
{

    public int[,] shopItems = new int[9, 9];
    public float cash;
    public Textual content CoinsTXT;


    void Begin()
    {
        CoinsTXT.textual content = "" + cash.ToString();

        //ID's
        shopItems[1, 1] = 1;
        shopItems[1, 2] = 2;
        shopItems[1, 3] = 3;
        shopItems[1, 4] = 4;
        shopItems[1, 5] = 5;
        shopItems[1, 6] = 6;
        shopItems[1, 7] = 7;
        shopItems[1, 8] = 8;

        //Value
        shopItems[2, 1] = 10;
        shopItems[2, 2] = 20;
        shopItems[2, 3] = 30;
        shopItems[2, 4] = 40;
        shopItems[2, 5] = 50;
        shopItems[2, 6] = 65;
        shopItems[2, 7] = 110;
        shopItems[2, 8] = 150;

    }


    public void Purchase()
    {
        GameObject ButtonRef = GameObject.FindGameObjectWithTag("Occasions").GetComponent<EventSystem>().currentSelectedGameObject;

        if (cash >= shopItems[2, ButtonRef.GetComponent<ButtonInfo>().ItemID])
        {
            cash -= shopItems[2, ButtonRef.GetComponent<ButtonInfo>().ItemID];
            CoinsTXT.textual content = "Cash:" + cash.ToString();

            Merchandise yourItem = new Merchandise(); //get your Merchandise from ID

            GameEvents.gameEvents.ItemPurchaseMade(yourItem);
        }


    }
}

GameEvents Script:

utilizing System;
utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;

public class GameEvents : MonoBehaviour
{
    public static GameEvents gameEvents;

    personal void Awake()
    {
        gameEvents = this;
    }

    public occasion Motion<Merchandise> onItemPurchase;

    public void ItemPurchaseMade(Merchandise ItemID)
    {
        if (onItemPurchase != null)
        {
            onItemPurchase(ItemID);
        }
    }
}

Stock Script:

utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;

public class Stock : MonoBehaviour
{

    personal Listing<Merchandise> itemList;

    public void Begin()
    {
        itemList = new Listing<Merchandise>();

        GameEvents.gameEvents.onItemPurchase += AddItem;

        Debug.Log("Stock");
    }

    public void AddItem(Merchandise merchandise)
    {
        itemList.Add(merchandise);
    }
}

Even when i take away Debug.Log it nonetheless exhibits nothing.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments