
[ad_1]
I buy Items from my store menu In-Game it would not present in my Inventory these are the images from the sport store and when i buy one thing and when i open the stock menu:
These are the scripts I’m utilizing for the Inventory and the store:
Shop Manager
utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;
utilizing UnityEngine.EventSystems;
utilizing UnityEngine.UI;
utilizing UnityEngine.GameBasis;
public class ShopManager : MonoBehaviour
{
public int[,] storeItems = new int[9, 9];
public float cash;
public Text CoinsTXT;
void Start()
{
CoinsTXT.textual content = "" + cash.ToString();
//ID's
storeItems[1, 1] = 1;
storeItems[1, 2] = 2;
storeItems[1, 3] = 3;
storeItems[1, 4] = 4;
storeItems[1, 5] = 5;
storeItems[1, 6] = 6;
storeItems[1, 7] = 7;
storeItems[1, 8] = 8;
//Price
storeItems[2, 1] = 10;
storeItems[2, 2] = 20;
storeItems[2, 3] = 30;
storeItems[2, 4] = 40;
storeItems[2, 5] = 50;
storeItems[2, 6] = 65;
storeItems[2, 7] = 110;
storeItems[2, 8] = 150;
}
public void Buy()
{
GameObject ButtonRef = GameObject.DiscoverGameObjectWithTag("Events").GetComponent<EventSystem>().currentSelectedGameObject;
if (cash >= storeItems[2, ButtonRef.GetComponent<ButtonInfo>().ItemID])
{
cash -= storeItems[2, ButtonRef.GetComponent<ButtonInfo>().ItemID];
CoinsTXT.textual content = "Coins:" + cash.ToString();
Item yourItem = new Item(); //get your Item from ID
GameEvents.recreationEvents.ItemPurchaseMade(yourItem);
}
}
}
GameEvents Script:
utilizing System;
utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;
public class GameEvents : MonoBehaviour
{
public static GameEvents recreationEvents;
personal void Awake()
{
recreationEvents = this;
}
public occasion Action<Item> onItemBuy;
public void ItemPurchaseMade(Item ItemID)
{
if (onItemBuy != null)
{
onItemBuy(ItemID);
}
}
}
Inventory Script:
utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;
public class Inventory : MonoBehaviour
{
personal List<Item> merchandiseList;
public void Start()
{
merchandiseList = new List<Item>();
GameEvents.recreationEvents.onItemBuy += AddItem;
Debug.Log("Inventory");
}
public void AddItem(Item merchandise)
{
merchandiseList.Add(merchandise);
}
}
Even when i take away Debug.Log
it nonetheless exhibits nothing.
[ad_2]