Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Strategy for Managing Power Ups

Discussion in 'Scripting' started by victorkhugo, Jul 18, 2014.

  1. victorkhugo

    victorkhugo

    Joined:
    Dec 4, 2013
    Posts:
    32
    I have a screen where you purchase power ups. What is the best attack to take about how to manage this.

    I need to :
    know how much gold the user has
    know if the gold available is enough to buy a certain power up.
    If the user has enough money and they click on the purchase button how do I relay that back to the system.

    This is all easy to do if it was just one power up, but because there are six of them, it doesn't make any sense to make six different scripts. Is there a way I can do this with just one script file?
     
  2. domkia

    domkia

    Joined:
    Aug 19, 2012
    Posts:
    99
    In this case I would use Dictionaries. 6 items with 2 parameters: string for name and int for price. Then just compare player's money with item price. If it can be aforded just save amount of owned items to PlayerPrefs.
     
  3. zDemonhunter99

    zDemonhunter99

    Joined:
    Apr 23, 2014
    Posts:
    478
    This.