- Home /
Using 2 arrays to change settings (ingame prices)
Hello,
I am currently trying to setup a shop for my game and would like to use two arrays to set the prices for the items.
I have these for my arrays at the moment:
public int [] _ownageLevel;
public float [] _curCost;
I would like to use the ownageLevel to determine what the curCost is. The ownageLevel starts at 0 and after they have purchased the item it will go to 1. Thereafter it will increase every time they upgrade the item (up to a maximum level). So if the ownageLevel is 0 in its own array, the curCost will be 0 in its own array, if the ownageLevel is 1 in its own array, the curCost will be 1 in its own array etc.
How can I increase the ownageLevel when they buy something and then also make sure that the curCost also increases at the same time? I don't want to have to make loads of if statements that explicitly set the value.
Cheers!
Answer by OrbitSoft · Oct 23, 2013 at 07:19 PM
You could achieve it by making a button like this
if (GUI.Button(Rect(0,0,100,100),"BUY")) {
_curCost[0] = _curCost[0] +(_curCost[0] * _ownageLevel[0]);
_ownageLevel[0] += 1;
}
Or a function:
void BuyItem(int id) {
_curCost[id] = _curCost[id] + (_curCost[id] * _ownageLevel[id]);
_ownageLevel[id] += 1;
}
And then using the function in a Button and every Button/Item has his own ID:
if (GUI/*button stuff*/) {
BuyItem(1);
}