Adding a cost reduction to my purchasable items
Hey, this should be pretty simple but am having troubles wrapping my head around it. Basically I am working on a game that has different items that the player can be. One of the premium buys is a price reduction on the items by 5% each time. I'm currently doing this through multiplying by *0.05. The problem with what am doing is that it multiplies the already reduced value by *0.05 on each additional purchase.
this is the sample code i got so far
if (( premiumCoins >= upgradeAmount) && (perkLevel <= 49) )
{
         premiumCoins = premiumCoins - upgradeAmount;
     for (int i = 0; i < 5; i++)
         {
         itemList[i].purchaseCost = itemList[i].purchaseCost - (itemList[i].purchaseCost * 0.05f);
         }
 
               }
Answer by TBruce · May 10, 2016 at 10:15 PM
Do something like this
 public ItemType[] itemList = new Array[10];
 private ItemType[] costList = new Array[10];
 private float currentDiscount = 1.0f;
 
 void Start()
 {
     costList = itemList;
 }
 
 void AddDiscount(float disc)
 {
     currentDiscount -= disc; // for example discount is 0.05f
 }
 
 itemList[i].purchaseCost = costList * currentDiscount;
 
              the result is pretty much the same though ;/ For example 250 coin cost ends up at 149 on 10 purchases. Should have been 125. And if i continue upgrade eventually the price gets nullified.
Yes I saw that immediately that is the reason for my change above. (note: personally I would make itemList & costList List's but I do not know how your code is set up and just figure you would modify it to match your code anyway.)
finally! That took way longer than it should have!! Thanks a bunch :)
Your answer