Quantcast
Channel: Answers for "Making a Market Script"
Viewing all articles
Browse latest Browse all 8

Answer by AngryOldMan

$
0
0

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


Viewing all articles
Browse latest Browse all 8

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>