Creating static objects/classes and managing currencies and items there is an easy way to do this.
For example, create a class like this
class GameData{
static int coins;
static readonly list<int>items=new list<int>();
public static bool BuyItem(intemId){
// purchasing process
if(coins>=10){
// I bought an item.
items.Add(itemId);
coins-=10;
return true;
} else{
// be short of money
return false;
}
}
}
If you add this script to the main scene, other scripts will not be able to
GameData.BuyItem(ItemId.hoge);
and so on, regardless of the scene.
© 2024 OneMinuteCode. All rights reserved.