Making a Market Script

I need a market script so that when a player enters a store and prompts the store owner, he will present a list of goods that the player can buy.

The items the player can buy will vary depending on the level of the player, so it will check the condition of the player's level script and if it's true, using a boolean will unlock it.

I need a way to set it up so that items can be added and viewed in the inspector using something like an array or list. When the menu is brought up, it will display the items unlocked in a GUI Label or something similar.

Any suggestions on how to accomplish this?

The items the player can buy will vary depending on the level of the player, so it will check the condition of the player's level script and if it's true, using a boolean will unlock it.

You chould create a class describing an item in the store. Each item has a "minimumlevel" variable. The item should also know how to render itself when it is disabled and when it is enabled, and it's enabled when players level >= minimum level. You could pass in the player info to the store, which pass in the player level to each item. I am envisioning myself the store as having a GUI script, and a List of store items. Each store item contains code to just draw its own GUI item. That way the store can just simply tell each item to draw when it goes through its array. These store items could also have useful data such as price, or maybe you pull that out from some referenced script.

When an item is clicked, a callback can be sent back to the player saying "You bought this item" or "You tried purchasing this item but are not of sufficient level" or "You tried purchasing this item but are out of funds". Maybe implement them as `function OnMarket(evt : MarketEvent)`.

I need a way to set it up so that items can be added and viewed in the inspector using something like an array or list

It sounds like you want to create your own Editor script. If you override OnInspectorGUI, you can make a custom GUI for your inspector and handle each item in a much more richer sense since you get full control. You could also define a new ScriptableObject which describe "a set of store items" that can be used in shops. That way you can easily trade one set of items for a shop keeper to another set of items. For example, a jeweler maybe doesn't want to sell swords and axes, or another region maybe sell power level weapons, in that region only. You could make an inspector for your scriptable type as well.

here is a basic frame for how to do it in Unityjava

var PlayerTalksToShopOwner : boolean = false;
var OpenShopGUI : boolean = false;
var Player : GameObject;
var PlayerLevel : int = 0;
var CashAmount : int = 0;
var BackGroundPos : Vector2 = new Vector2(10,10);
var BackGroundSize : Vector2 = new Vector2(10,10);
var ShopContentPos : Vector2 = new Vector2(10,10);
var ShopContentSize : Vector2 = new Vector2(10,10);
var ButtonSize : Vector2 = new Vector2(10,10);
var Button1Pos : Vector2 = new Vector2(10,10);
var Button2Pos : Vector2 = new Vector2(10,10);
var Price1 : int = 100;
var Price2 : int = 200;
var Price3 : int = 300;
var Price4 : int = 400;

function Awake()
{
    if (Player == null)
    {
        //use find with tag or any method you prefere to locate your player
    }
}

function Update ()
{
    if (PlayerTalksToShopOwner == true)
    {
        CheckPlayersLevel ();
        OpenShopGUI = true;
    }
}

function CheckPlayersLevel()
{
    LVcheck = Player.GetComponent (PlayerScript);
    PlayerLevel = LVcheck.Level;
    CashAmount = LVcheck.Money;
}

function OnGUI ()
{
    if (OpenShopGUI == true);
    {
        //Draw shop interface, start with the background
        GUI.BeginGroup (new Rect (BackGroundPos.x,BackGroundPos.y,BackGroundSize.x,BackGroundSize.y));

        GUI.BeginGroup(new Rect (ShopContentPos.x,ShopContentPos.y,ShopContentSize.x,ShopContentSize.y));
        //check the players level and open the right shop
        if (PlayerLevel >= 0 && PlayerLevel <= 10)
        {
            //Draw buttons so that you can buy something
            if (GUI.Button (new Rect (Button1Pos.x,Button1Pos.y,ButtonSize.x,ButtonSize.y)) && CashAmount >= Price1)
            {
                //add item you just bought to inventory
                CheckMoney.Money = CheckMoney.Money - Price1;
            }
            if (GUI.Button (new Rect (Button2Pos.x,Button2Pos.y,ButtonSize.x,ButtonSize.y)) && CashAmount >= Price2)
            {
                //add item you just bought to inventory
                CheckMoney.Money = CheckMoney.Money - Price2;
            }
        }
        if (PlayerLevel >= 11 && PlayerLevel <= 20)
        {
            //Draw buttons so that you can buy something
            if (GUI.Button (new Rect (Button1Pos.x,Button1Pos.y,ButtonSize.x,ButtonSize.y)) && CashAmount >= Price3)
            {
                //add item you just bought to inventory
                CheckMoney.Money = CheckMoney.Money - Price3;
            }
            if (GUI.Button (new Rect (Button2Pos.x,Button2Pos.y,ButtonSize.x,ButtonSize.y)) && CashAmount >= Price4)
            {
                //add item you just bought to inventory
                CheckMoney.Money = CheckMoney.Money - Price4;
            }
        }
    }
}

it's mainly GUI based scripting but also partly checking your players script to see what level you are and if you have the money

Maybe you can start off checking what level the player is, using a IF statement maybe, then, depending on what level the player turns out to be, you can choose to show a specific GUI for that level, containing different good, depending on what level the player is.

I'm not quite sure if thiw will work or not, since you can't do the GUI function inside a update function, but i'm sure you'll work that out!

For unlocking a object that the player bought, you can use a IF statement to, set a var to 1 if it's bought, 0 if it isn't, then simply check what value the var has, and activate the gameObject that the player bought, if the var is 1.

There is no easy answer for this question because you are not very clear on what your environment looks like.Do you already store the items, are there already scripts for the player or the store keeper, have you modified the GUI system at all, are you using a database, ect. If you want a very specific answer to this question you need to provide more information on what we are working with. Since you asked the question in a general way I will answer it general way.

First "I need a way to set it up so that items can be added and viewed in the inspector"

Like you mentioned the best way to achieve this part is a public list, lets put this list in the store keepers script.

public List<string> listedItems;

The best bet for dealing with the individual items would be to store them in a database along side their value, level, and other unique attributes. Setting up that database is a topic for another time, but for this discussion lets assume you already have a way to store items and their levels.

The next part would be to build the list for the menu, so when the store keeper is clicked he could ask the player he is, lets assume you have a basic get set on the player for his level.

playersLevel = player.PlayersLevel()

And now that we have the players level we can build the list, I would add the name of the items to our public list listItems (allowing us to see the menu items in the inspector). And finally make the list in the GUI.

Borrowing some code from Bobadebob

EDIT i cant seem to make the code tags work, but you can use the code Bobadebob posted, but I would foreach though the string list, and match the items with the ones in your data base.

Really I would like to address this question with a more honest/direct answer but I need better details from you. Good luck.